VBA Bug

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,220
Hello All

Could someone help on this please.
The code below is in the "Thisworkbook" module and when you click on save the code saves the sheet to the correct path and names the file with data from B13 and G13.
This code keeps bugging out on line "Me.SaveAs Filename:=Fname, FileFormat:=52", any idea's on how to fix this.
I am using excel 2007



Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim Fname As String
Cancel = True
Application.EnableEvents = False
Fname = "S:\Branch Data\test office\testing\CAT no\" & Sheets("Sheet1").Range("B13").Value & " " & Format(Sheets("Sheet1").Range("G13").Value, "dd-mm-yyyy") & ".xlsm"
MsgBox Fname
Me.SaveAs Filename:=Fname, FileFormat:=52
Application.EnableEvents = True
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
does this path exist?

S:\Branch Data\test office\testing\CAT no\

does sheet1 B13 have some data?

check theses
 
Upvote 0
Try not specifying the FileFormat in the SaveAs.
 
Upvote 0
You have MsgBox Fname, so when it goes wrong next:
(a) tell us the error message
(b) in the Immediate Pane of the VBE (Ctrl+G if you can't see it) type:
?Fname
and press Enter, then paste the results here - it could be the filename has some illegal characters in it.
 
Upvote 0
Maybe just my blind eyes, but in addition to venkat's, Norie's, and Pascal's observations - I do not see where you are preventing recurse. Not tested, but I am windering if the "bugging out" might be a continuous loop. Save/BeforeSave/Cancel/BeforeSave calls a Save/..........
 
Upvote 0
Thank you to all for your comments, It turn out that the path was not correct
Many thanks to all
 
Upvote 0

Forum statistics

Threads
1,224,604
Messages
6,179,857
Members
452,948
Latest member
UsmanAli786

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