ensure correct workbook

hitch_hiker

Active Member
Joined
Feb 21, 2012
Messages
294
I am saving "save as" a workbook, when I am doing this I expect 3 workbooks will be open at the same time, also because I am using a keyboard shortcut "ctrl j" I need to avoid a typo saving any other workbook I happen to be in to be saved as and more importantly overwrite the intended file.
I plan on
VBA Code:
workbooks(invoice register).activate
my logic is even if the file is closed, the macro will open the file and save it.
1? would this be the correct way, or is there a better way?
2? would I need to include the complete path and what would be the sytntax for that.
Sorry for the really easy question, my search so far hasn't directly addressed my situation
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
This is a Windows (and probably mac) functionality - the os will not allow you to save over any file that's already open. You'll get an error from excel that saving is not possible. Saving a file with the full path is very simple - just input the full path (including the extension) as a string, i.e.,
VBA Code:
WorkbookName.SaveAs "C:\Temp\Encoding Time.csv"

I'm not entirely sure what you are trying to accomplish with the .Activate - that will only put focus on the specified workbook if it is already open, and will error if the specified workbook is not open. If you are trying to see if the workbook name entered is one of the ones you have open, you can use an if statement to help, i.e., in pseudocode, if workbookname = prohibitedname1 or if workbookname = prohibitedname2 .... then .... end if
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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