Defining the variable to make code simplier

maxon

New Member
Joined
Oct 28, 2015
Messages
43
Hello Guys,

Could you please advice how to define below lines to make it simplier:

Code:
nome_file_master1 = "1011130800H - " & data_file6 & ".xlsx"

Workbooks.Open Filename:=ThisWorkbook.Path & "\" & data_anno & "\" & data_mese2 & "\" & data_file3 & "\RUSSELL\" & nome_file_master1 & ""

Set wb2 = Workbooks("1011130800H - " & data_file6 & ".xlsx").Sheets("Sheet1")

thanks!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I would define wrk variable as a Workbook object and open the workbook by setting this object variable and use it in the following sections in the procedure:

Something like this:

Code:
Dim wrk as Workbook


nome_file_master1 = "1011130800H - " & data_file6 & ".xlsx"


Set wrk = Workbooks.Open(Filename:=ThisWorkbook.Path & "\" & data_anno & "\" & data_mese2 & "\" & data_file3 & "\RUSSELL\" & nome_file_master1 & “”)


Set wb2 = wrk.Sheets("Sheet1")

Note: I suggest defining all your variables as a good habit besides its advantages. I didn't do that in your code for your other variables - nome_file_master1, wb2

Suat
 
Upvote 0

Forum statistics

Threads
1,215,353
Messages
6,124,464
Members
449,163
Latest member
kshealy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top