Hi,
I have a daily report delivered in CSV format. I do a fair bit of manipulation in a series of macros and then save the file. When I run this on my PC it works fine. When I save the macros to an add-in file format so that others can access them, all of the procedures work except the following save file routine. I am relatively new to macro programming so please forgive any poor style issues. I just don’t understand why this will work on my PC but not as an add-in for others.
Any suggestions?
Cheers,
Rod
====================================
Sub Save_DSS_Daily()
'
' Save the daily report
Dim savefile As String
Dim saveyear As Integer
Dim yearpath As String
Dim i As Integer
On Error GoTo HandleFileError
saveyear = Year(Date)
sheetname = ActiveSheet.Name
yearpath = "Z:\Activity Diagnostic Reports DSS\" & saveyear
filepath = yearpath & "\DSS CSV Files"
savefile = filepath & "\" & sheetname & ".xlsm"
'Futureproofing - if the year changes set up new directory structure
If Dir(yearpath, vbDirectory) = "" Then
MkDir Path:=yearpath
If Dir(filepath, vbDirectory) = "" Then
MkDir Path:=filepath
i = MsgBox(filepath & Chr(13) & Chr(13) & "New directory created for - " & saveyear)
End If
End If
'Save the file
ActiveWorkbook.SaveAs Filename:= _
savefile _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
i = MsgBox(sheetname & ".xlsm" & Chr(13) & Chr(13) & "Saved in:" & Chr(13) & filepath, , "File Saved")
Exit Sub
'If an error, remind the user to save the file
HandleFileError:
i = MsgBox(" Please save as:" & Chr(13) & Chr(13) & sheetname & ".xlsm" & Chr(13) & Chr(13) & " To the directory:" & Chr(13) & Chr(13) & filepath, , "Save file")
End Sub
========================
I have a daily report delivered in CSV format. I do a fair bit of manipulation in a series of macros and then save the file. When I run this on my PC it works fine. When I save the macros to an add-in file format so that others can access them, all of the procedures work except the following save file routine. I am relatively new to macro programming so please forgive any poor style issues. I just don’t understand why this will work on my PC but not as an add-in for others.
Any suggestions?
Cheers,
Rod
====================================
Sub Save_DSS_Daily()
'
' Save the daily report
Dim savefile As String
Dim saveyear As Integer
Dim yearpath As String
Dim i As Integer
On Error GoTo HandleFileError
saveyear = Year(Date)
sheetname = ActiveSheet.Name
yearpath = "Z:\Activity Diagnostic Reports DSS\" & saveyear
filepath = yearpath & "\DSS CSV Files"
savefile = filepath & "\" & sheetname & ".xlsm"
'Futureproofing - if the year changes set up new directory structure
If Dir(yearpath, vbDirectory) = "" Then
MkDir Path:=yearpath
If Dir(filepath, vbDirectory) = "" Then
MkDir Path:=filepath
i = MsgBox(filepath & Chr(13) & Chr(13) & "New directory created for - " & saveyear)
End If
End If
'Save the file
ActiveWorkbook.SaveAs Filename:= _
savefile _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
i = MsgBox(sheetname & ".xlsm" & Chr(13) & Chr(13) & "Saved in:" & Chr(13) & filepath, , "File Saved")
Exit Sub
'If an error, remind the user to save the file
HandleFileError:
i = MsgBox(" Please save as:" & Chr(13) & Chr(13) & sheetname & ".xlsm" & Chr(13) & Chr(13) & " To the directory:" & Chr(13) & Chr(13) & filepath, , "Save file")
End Sub
========================