Click here to Skip to main content
14,694,505 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all.
I am trying to create a new workbook and save it to a file (file name depend on variable)




But Stille error "
Run time error 1004
Application define or object- define error.

Please help me.

What I have tried:

I have try:
 Set fRwB = Workbooks.Add
fRwB.Sheets.Add().Name = "Company Name"
  sFile = outPath & "\" & Format(sdate, "yymm") & ".xlsx"
  fRwB.Save Filename:=sFile, FileFormat:=51
  myFile = Dir
Posted
Updated 25-Mar-18 3:10am
v2
Comments
Patrice T 25-Mar-18 0:07am
   
vba also tell you the line of error

1 solution

Check this:
Dim wbk As Workbook
Dim wsh As Worksheet
Dim sFile As String

sFile = outPath & "\" & Format(sdate, "yymm") & ".xlsx"
Set wbk = Application.Workbooks.Add
Set wsh = wbk.Worksheets(1)
wsh.Name = "Company Name"
wbk.SaveAs sFile

Set wsh= Nothing
Set wbk = Nothing


For further details, please see: Workbook.SaveAs Method (Excel)[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900