Inserting Path to VBA

sanilmathews

Board Regular
Joined
Jun 28, 2011
Messages
102
Hi,

I have this simple Workbook open code with the given path as reference.

Code:
Workbooks.Open Filename:="D:\Checklist Folder\Temp\Sample Checklist.xls"

Where the above code will open the "Sample Checklist.xls" from the above mentioned path. However path mentioned above will vary and user have to go to VBA editor to change the path to open the Sample Checklist workbook.

I would not want the user to go into the VBA editor since that would expose the codes to be altered. Will it be possible to mention the path in a cell and the code to refer that cell to identify the mentioned path?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try like this

Code:
Workbooks.Open Filename:=Sheets("Sheet1").Range("A1").Value & "Sample Checklist.xls"
 
Upvote 0
Thanks for your response. It worked just fine. Now I am actually giving the codes that I really had trouble with.

Code:
Dim lr As Long
Dim i As Long
Dim twb As Workbook
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set twb = ActiveWorkbook
lr = Cells(Rows.Count, 1).End(xlUp).Row
rwcnt = lr - 2
On Error GoTo ErrHandler:
Workbooks.Open Filename:=Sheets("Sheet1").Range("A12").Value & "Sample Checklist.xls"
For i = lr To 2 Step -1
    
[B]ActiveWorkbook.SaveAs Filename:=[I]"D:\Checklist Folder\Temp\"[/I] & twb.Sheets("Template").Range("K" & i).Value & ".xls"[/B]
Application.StatusBar = Format(1 - (i / lr), "00% Completed")
Next i
ActiveWorkbook.Close
twb.Activate     
Application.StatusBar = ""

I would like to have the same implemented in the above bolded code.

Thank you once again!
 
Upvote 0
ADVERTISEMENT
Could any one please let me know if the above request is possible?

Thanks
 
Upvote 0
ADVERTISEMENT
I tried to do edit like the below and it throwing me error.

Code:
[B]ActiveWorkbook.SaveAs Filename:=[I]Sheets("Sheet1").Range("A12").Value[/I] & twb.Sheets("Template").Range("K" & i).Value & ".xls"[/B]

I may be wrong in the above logic.
 
Upvote 0
What is in

Sheets("Sheet1").Range("A12")

and

twb.Sheets("Template").Range("K" & i)
 
Upvote 0
Sheet1 Cell A12 will have the path that the code uses to save the copies of workbook.

Template Sheet Column K will have the list of names which the copies of workbook gets renamed.
 
Upvote 0
Maybe

Rich (BB code):
ActiveWorkbook.SaveAs Filename:=Sheets("Sheet1").Range("A12").Value & "\" & twb.Sheets("Template").Range("K" & i).Value & ".xls"
 
Upvote 0

Forum statistics

Threads
1,196,279
Messages
6,014,423
Members
441,818
Latest member
itsfaisalkhalid

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