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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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