I've recently upgraded to 2007, and for the most part, my VBA seems to work. This is one of the odd, rare occasions where this is not true:
Workbook's purpose: serve as a "kickoff" processor (I give it a list of workbooks, it opens them in turn and runs the code saved in each one.)
One of the modules in the kickoff book has a collection of functions which are commonly used among the other workbooks. One of the functions just saves the book to a specific, dynamically defined folder. Currently I'm keeping everything in 2003 format, as such, I specify the format in the .SaveAs method.
Code is as follows:
Kickoff Book:
One of the reports (they all get the same error)
And the function module (Just the one giving me problems):
bolded code is where I receive this error:
Runtime Error '1004':
Method 'SaveAs' of object '_Workbook' failed
I've tried removing the fileformat value, which does save the file, however it's saved in 2007 format with the .xls extension.
I've recreated the steps necessary to run this exact scenario in completely new workbooks, but that seems to work just fine. I suspect something isn't working with my path string, but I know for certain that the path is correct, because I've copied the value of the variable and fed it into Explorer, and it pulls up the right folder.
Anyone have any ideas on what could be causing this?
Workbook's purpose: serve as a "kickoff" processor (I give it a list of workbooks, it opens them in turn and runs the code saved in each one.)
One of the modules in the kickoff book has a collection of functions which are commonly used among the other workbooks. One of the functions just saves the book to a specific, dynamically defined folder. Currently I'm keeping everything in 2003 format, as such, I specify the format in the .SaveAs method.
Code is as follows:
Kickoff Book:
Code:
Sub main()
'Main and report books
Dim masterBook As Workbook, wkgBook As Workbook
'Paths
Dim wkgFolder As String, histFolder As String, dbFolder As String
'timeframe variables
Dim weDate As Date, fy As String, period As String, week As String
'checkbox variables
Dim rptRun As Boolean, rptHist As Boolean, rptDB As Boolean, rptVerify As Boolean
'Report Name
Dim rpt As Range
Set masterBook = ActiveWorkbook
wkgFolder = masterBook.Sheets("Main").Range("wkg").Value
histFolder = masterBook.Sheets("Main").Range("hst").Value
dbFolder = masterBook.Sheets("Main").Range("db").Value
weDate = masterBook.Sheets("Main").Range("we").Value
fy = masterBook.Sheets("Main").Range("fy").Value
period = masterBook.Sheets("Main").Range("pd").Value
week = masterBook.Sheets("Main").Range("wk").Value
rptRun = masterBook.Sheets("Main").runbox.Value
rptHist = masterBook.Sheets("Main").histbox.Value
rptDB = masterBook.Sheets("Main").dbbox.Value
rptVerify = masterBook.Sheets("Main").verifybox.Value
'Now, to loop through the report list and run macros for each one.
For Each rpt In masterBook.Sheets("Main").Range("reports")
If rpt = Empty Then
GoTo skip
Exit Sub
Else
macroName = "'" & rpt.Value & "'!subordinate_macro.subordinate_macro"
Set wkgBook = Workbooks.Open(Filename:=masterBook.Sheets("Main").Range("wkg").Value & rpt.Value, UpdateLinks:=False)
Application.Run macroName, rptRun, rptHist, weDate, rptDB, rptVerify, wkgFolder, histFolder, dbFolder, masterBook.Name, rpt.Value
wkgBook.Close
End If
skip:
Next rpt
MsgBox "List completed."
End Sub
One of the reports (they all get the same error)
Code:
Sub subordinate_macro(ByVal rptRun As Boolean, _
ByVal rptHist As Boolean, _
ByVal weDate As Date, _
ByVal rptDB As Boolean, _
ByVal rptVerify As Boolean, _
ByVal wkgFolder As String, _
ByVal histFolder As String, _
ByVal dbFolder As String, _
ByVal masterbook As String, _
ByVal rpt As String)
'Run
If rptRun Then
ActiveWorkbook.RefreshAll
Sheets(3).Name = "WE " & Format(weDate, "mm-dd-yy")
End If
'Verify
If rptVerify Then
macroName = "'" & masterbook & "'!stdfn.stdVerify"
Application.Run macroName, masterbook
End If
'History
If rptHist Then
ActiveWorkbook.Save
macroName = "'" & masterbook & "'!stdfn.stdHist"
Application.Run macroName, histFolder, rpt, weDate
End If
'Databank
If rptDB Then
'Paste Values
macroName = "'" & masterbook & "'!stdfn.stdPV"
Application.Run macroName
'Save
macroName = "'" & masterbook & "'!stdfn.stdDB"
Application.Run macroName, dbFolder, rpt
End If
End Sub
And the function module (Just the one giving me problems):
Code:
Sub stdHist(ByVal histFolder As String, _
ByVal rpt As String, _
ByVal weDate As Date)
Dim rwb As Workbook
Dim hfile As String
Set rwb = Workbooks(rpt)
hfile = histFolder & Left(rpt, Len(rpt) - 4) & " we" & Format(weDate, "mmddyy") & ".xls"
Application.DisplayAlerts = False
° [b]rwb.SaveAs hfile, xlExcel8[/b]
Application.DisplayAlerts = True
Set rwb = Nothing
End Sub
Runtime Error '1004':
Method 'SaveAs' of object '_Workbook' failed
I've tried removing the fileformat value, which does save the file, however it's saved in 2007 format with the .xls extension.
I've recreated the steps necessary to run this exact scenario in completely new workbooks, but that seems to work just fine. I suspect something isn't working with my path string, but I know for certain that the path is correct, because I've copied the value of the variable and fed it into Explorer, and it pulls up the right folder.
Anyone have any ideas on what could be causing this?