Problem with SaveAs Method

cicconmr

Board Regular
Joined
Jul 5, 2011
Messages
90
Code:
    Dim mcDate As String
    Dim mcDocName As String
    
    myDate = Day(Now)
    Worksheets("Index Changes").Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    Worksheets("data").Delete
    Worksheets("Funding Data").Delete
    Worksheets("Tables").Delete
    
    mcDate = InputBox("What is today's date?", "Save File As...")
    mcDocName = "SP Changes " & mcDate & ".xls"

    ActiveDocument.SaveAs Filename:=mcDocName, FileFormat:=wdFormatXMLDocument

I'm getting an Object Required error (424), not sure where that is coming in at, I'm assuming on the string mcDocName? What am I doing wrong there....?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I'm not sure what ActiveDocument refers to, if you want to save your workbook, then it should be:

ActiveWorkbook.SaveAs

Though coincidentally, you have pointed out a potential bug in your code. If you don't test the results of the inputbox, then your user could theoretically type in invalid file name characters. Several of your punctuation characters, other than a period, are invalid.
 
Upvote 0
I changed it to ActiveWorkbook.SaveAs and am now getting another run-time error

"SaveAs method of Object _Workbook Failed"

Not sure what that means? Am I writing out the method properly? Can I do it like this

ActiveWorkbook.SaveAs(mcDocName,wdFormatXMLDocument)?
 
Upvote 0
Filename should be the complete path.
Perhaps

Code:
With ActiveDocument
    .SaveAs Filename:=.Path & Application.PathSeparator & mcDocName, FileFormat:=wdFormatXMLDocument
End With
 
Upvote 0
ActiveWorkbook.SaveAs(mcDocName,wdFormatXMLDocument)?

I wouldn't imagine Excel would know what wdFormatXMLDocument is - it's part of the Word object model.

Try typing ?wdFormatXMLDocument in the VBA Immediate window in Excel and then try it again in Word.

Where did you get this code? It appears to be written to run in Word rather than Excel.
 
Upvote 0
That is probably the problem, I was looking at the library online but I must have been in Micrsoft Word?

What is the appropriate Excel code for a save as?

ActiveWorkbook.SaveAs Filename:=mcDocName, FileFormat:=xlXMLSpreadsheet

?
 
Upvote 0
Yes that worked, just have to be sure that in my input box there are no characters as mentioned earlier.

Problem solved, thank you guys for noting that!
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,768
Members
452,940
Latest member
rootytrip

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