VBA linked to a check box to save excel file

Jmoz092

Board Regular
Joined
Sep 8, 2017
Messages
184
Office Version
  1. 365
  2. 2011
Platform
  1. Windows
  2. MacOS
Hi , I'm having trouble creating a check box to "save as" for one of my excel projects. I want the VBA to generate the name of the file based on some cells within a sheet of the workbook. Also,some of the save path on my network can be determined by data within some cells on the same sheet. I've attempted to write a code to do this, but am not having any luck. Any help/education would be greatly appreciated.

<code>
Sub saveastest()
Dim thisfile As Range
ChDir “z:\pathfolder1\pathfolder2\pathfolder3\” & Range(“AC1”)\” & Range(“AC2”)\.Value, FileFormat:=51"
thisfile = Range("AC3").Value
ActiveWorkbook.SaveAs Filename:=thisfile, FileFormat:=51
End Sub
</code>

 
Re: Help with VBA linked to a check box to save excel file

Is that a valid path and is the filename what you expected?

Yes, the file path and name of the file in that code string is the way it's supposed to be. But the problem is that the file is now named that whole code string. And, it's not actually saving or savingAs now.

The name of the file now is:
"z:\filepath1\filepath2\filepath3\September 2017\September 20,2017\lastName, firstName September-20-2017"

The name of the file should be:
"lastName, firstName September-20-2017"

Also, I want to thank you all for your time,help, and education on this issue.
 
Last edited:
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Re: Help with VBA linked to a check box to save excel file

That doesn't quite add up, can you post the exact current code?
 
Upvote 0
Re: Help with VBA linked to a check box to save excel file

That doesn't quite add up, can you post the exact current code?


in module 1, the code is (exactly):

Code:
Sub saveastest()




    Dim thisfile As String
    Dim FilePth As String
    
    FilePth = "z:\data\officeforms\ultrasoundorders\" & Range("AC1").Value & "\" & Range("AC2").Value & "\"
    thisfile = Range("AC3").Value
    ActiveWorkbook.SaveAs FilePth & thisfile, FileFormat:=51




End Sub
 
Upvote 0
Re: Help with VBA linked to a check box to save excel file

Try changing
Code:
FileFormat:=51
to
Code:
FileFormat:=52
From
https://www.rondebruin.nl/mac/mac020.htm


When I change it to File Format 52, a box pops up that visual basic macros will be removed if I save the file in this format, etc, etc. When I cancel save, the debugger highlights the last line of the VBA as yellow.
 
Last edited:
Upvote 0
Re: Help with VBA linked to a check box to save excel file

In that case use 53
 
Upvote 0
Re: Help with VBA linked to a check box to save excel file

In that case use 53

I used 57, per Ron's layout (I'm using Excel Mac 2011), and then took out "Z:" and I got the file to save to the top level of our network directory, but it named the file the whole length of the save path concatenated with the intended name of the file

Code:
Sub saveastest()




    Dim thisfile As String
    Dim FilePth As String
    
    FilePth = "filepath1:\filepath2\filepath3\" & Range("AC1").Value & "\" & Range("AC2").Value & "\"
    thisfile = Range("AC3").Value
    ActiveWorkbook.SaveAs FilePth & thisfile, FileFormat:=57




End Sub
 
Upvote 0
Re: Help with VBA linked to a check box to save excel file

I'm using Excel Mac 2011

Think that might be where the fault lies, Mac and Windows file paths aren't the same.

Here's an example of SaveAs for Mac 2011 from Ron de Bruin's site.
Code:
ActiveWorkbook.SaveAs "Macintosh HD:Users:YourUserName:Desktop:ron.xlsm", fileformat:=53
 
Upvote 0
Re: Help with VBA linked to a check box to save excel file

Think that might be where the fault lies, Mac and Windows file paths aren't the same.

Here's an example of SaveAs for Mac 2011 from Ron de Bruin's site.
Code:
ActiveWorkbook.SaveAs "Macintosh HD:Users:YourUserName:Desktop:ron.xlsm", fileformat:=53


Always something simple huh? I'll give this a go and report back.

This fileformat number applies to only the workstation that is using excel to create/edit/save the file at the moment right? We have Mac and MS workstations throughout our office and also utilize different versions of Excel at different workstations. :)

So I'll need to create multiple check boxes to use for each of these variants then?
 
Upvote 0
Re: Help with VBA linked to a check box to save excel file

Think that might be where the fault lies, Mac and Windows file paths aren't the same.

Here's an example of SaveAs for Mac 2011 from Ron de Bruin's site.
Rich (BB code):
ActiveWorkbook.SaveAs "Macintosh HD:Users:YourUserName:Desktop:ron.xlsm", fileformat:=53


With the user utilizing excel 2011 for Mac, the code should then be:??

Code:
[COLOR=#454545][FONT=Helvetica Neue][I]Sub saveastest()[/I][/FONT][/COLOR]
[COLOR=#454545][FONT=Helvetica Neue]
[/FONT][/COLOR]
[COLOR=#454545][FONT=Helvetica Neue]
[/FONT][/COLOR]
[COLOR=#454545][FONT=Helvetica Neue][I]    Dim thisfile As String[/I][/FONT][/COLOR]
[COLOR=#454545][FONT=Helvetica Neue][I]    Dim FilePth As String[/I][/FONT][/COLOR]
[COLOR=#454545][FONT=Helvetica Neue][I]    FilePth = "z:filepath1:filepath2:filepath3:” & Range("AC1").Value & “:” & Range("AC2").Value & “:”[/I][/FONT][/COLOR]
[COLOR=#454545][FONT=Helvetica Neue][I]    thisfile = Range("AC3").Value[/I][/FONT][/COLOR]
[COLOR=#454545][FONT=Helvetica Neue][I]    ActiveWorkbook.SaveAs FilePth & thisfile, FileFormat:=53[/I][/FONT][/COLOR]
[COLOR=#454545][FONT=Helvetica Neue]
[/FONT][/COLOR]
[COLOR=#454545][FONT=Helvetica Neue]
[/FONT][/COLOR]
[COLOR=#454545][FONT=Helvetica Neue][I]End Sub[/I][/FONT][/COLOR]
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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