Felix18807
Programmer
I generate routine excel reports (in access) for a user and then email him the result. The problem he is encountering is that he frequently launches the file directly from outlook and forgets to save it locally. Any work he does on the file is subsequently lost.
To help with this issue I can think of a few solutions but I think only two seem really feasable.
1) Save the file in a shared drive and post him the link instead of the file.
2) Insert a macro into the created excel file that saves the file to his personal file when he launches it.
Solution 1 is straight forward and achievable but I would not no how to approach 2 as it would need the ability to insert code into an excel file via access.
My question is how hard is it going to be to acheive solution 2?
I made this bit of code but I've no idea how to insert it into the excel file automatically.
To help with this issue I can think of a few solutions but I think only two seem really feasable.
1) Save the file in a shared drive and post him the link instead of the file.
2) Insert a macro into the created excel file that saves the file to his personal file when he launches it.
Solution 1 is straight forward and achievable but I would not no how to approach 2 as it would need the ability to insert code into an excel file via access.
My question is how hard is it going to be to acheive solution 2?
I made this bit of code but I've no idea how to insert it into the excel file automatically.
Code:
Function FileOrDirExists(PathName As String) As Boolean
On error resume next
Dim iTemp As Integer
iTemp = GetAttr(PathName)
Select Case Err.Number
Case Is = 0
FileOrDirExists = True
Case Else
FileOrDirExists = False
End Select
End Function
Code:
Private Sub Workbook_Open()
Dim myDir as string
myDir= "U:\" & thisworkbook.name
if FileOrDirExists(mydir) then
Msgbox "This file exists. Please save as a different mane"
else
ActiveWorkbook.SaveAs Filename:=mydir , FileFormat:=xlExcel8, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
End Sub