Extract File name and read that name as workbook

satya12

Board Regular
Joined
Oct 19, 2021
Messages
70
Office Version
  1. 2016
Platform
  1. Windows
Hi All,
I am having 2 modules in one macro, in the 1st module the file will open using filepath this filepath will be taken from sheet1 cell, i will take the path and open that file.
But when i use 2 module how to read the workbook name .
because the file will change some times. for module1 it will direct taken from the cell value , but how 2nd module will take
VBA Code:
Set Price = Workbooks.Open(Filename:=(Macrohome.Range("D6").Value))

[/CODE[CODE=vba]
Dim Strpath as string
Dim StrFile as string

Strpath = Macrohome.Range("D6").Value
StrFile = Right(Strpath, Len(Strpath) - InStrRev(Strpath, "\"))
Set Price = Workbooks.StrFile
]
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
try the following
1638622256274.png


first procedure, passes the file name in strfile and second procedure, shows the name of the strfile in a msgbox. Note 1st line of code, this will make strfile accessible to other sub procedures.

hth....
 
Upvote 0

Forum statistics

Threads
1,215,047
Messages
6,122,858
Members
449,096
Latest member
Erald

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