Runtime error for savefile

mysticmario

Active Member
Joined
Nov 10, 2021
Messages
323
Office Version
  1. 365
Platform
  1. Windows
There's this one line of code that throws runtime error at me
VBA Code:
        wbNew.SaveAs Filename:=wbaddress & "/" & wbname2 & ".xlsm", _
            FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
, but the best thing is I used to run this line of code without a problem when i had premade buttons on the sheet. Now when my buttons are being created "on the fly" when new sheet is being created it suddenly stopped running, can anyone help me figure out what happened?

1665146147298.png
 
wbname is whatever you type in inputbox e.g. "test file"
so full line for wbNew.SaveAs Filename:=C:\Users\Projektant\OneDrive - ART-PRO Sp. z o.o\Wyceny\test file.xlsm , _
where:
wbadress = C:\Users\Projektant\OneDrive - ART-PRO Sp. z o.o\Wyceny
wbname2 = "test file"
 
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.
I tried switching
wbNew.SaveAs Filename:=wbaddress & "/" & wbname2 & ".xlsm", _ FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
to:
wbNew.SaveAs Filename:=wbaddress & "/" & wbname & ".xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

where :
wbname = ActiveSheet.Name
Last thing i did was creating a static name:
wbNew.SaveAs Filename:=wbaddress & "/" & "test file" & ".xlsm", _ FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

and this also failed
- so i used now inputbox data stroed as strign in avriable = didnt work
- i used activesheet.name stored as string in variable = didnt work
- I even used static data instead fo variable = also didnt work

The problem has to besomewhere else which is weird beacuse the same code worked fine when I had it in premade buttons.
Now when tyhe buttons are autocreated the macro works until the savefile part of routine.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,886
Messages
6,122,093
Members
449,064
Latest member
Danger_SF

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