VBA: Dynamic Save Loaction

SteveOranjin

Board Regular
Joined
Dec 18, 2017
Messages
170
Hello,

I have a macro set up that is designed to copy all of the data in a particular tab on a sheet, and transfer it to a new sheet, and then to save that sheet. I'm wondering something though, since all of the folders that I save data sheets in have a certain naming convention to them, is there a way that I can have excel capture that so the data I'm saving is always moved to the right folder?

Here is an example:

Rich (BB code):
Sub Copy_Save_Workbook()    '~~> This will create a new workbook with the relevant sheet
    ThisWorkbook.Sheets("Data Sheet").Copy


    '~~> Save the new workbook
    ActiveWorkbook.SaveAs "M:\Vendor Product Data\Site Light (SLT)\Data Loads (SLT)", FileFormat:=51
End Sub

The part that changes for the folders is highlighted in Green. That data ALWAYS ALWAYS enter every sheet I make. It is also contained in "Macro!M10" (That is the first section of the highlight) and "Macro!N10" (that is contained in the second part of the highlight.)

Hope you are well,

Steve
 
When you say that "it doesn't like that", what do you mean exactly? Do you get an error? If so, which one? Also, it might help if you posted the actual values contained in M10, N10, and B3.

When I run the above code, it says specifically, "Run-time error '1004': "Method 'SaveAs' of object '_workbook' failed."

Cell B3 Contains, "File Name"has The content it has in it is "BALFinishUpdate041618"
Cell M10 Contains "Brand Name. The current value of M10 is "Special Lite"
Cell N10 Contains "Brandcode". It currently has the value "SLT in it.

The header of each one is "File Name", "BrandName" and "Brandcode" respectively.

Please let me know if there are any other questions you have.
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
With those values, the string resolves to...

Code:
M:\Vendor Product Data\Special Lite (SLT)\Data Loads (SLT)\BALFinishUpdate041618

Is the path correct? What happens when you manually save to that folder? Also, earlier you had "Special Light" instead of "Special Lite". Which one should it be? Could this be the issue?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
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