M
majd.alwajeeh
Hello,
I'm new to VBA, but it seems quite powerful sometimes. We have a
system, where the user browses to a folder on the server, and opens his
choice of excel file. In this excel file, there is a form, with some
VBA in the background, where one can fill out the form and press a
control button in the excel file, which will place the gathered
information in the excel into a word template with the same name. This
word template exists in the same folder as the excel files.
The assumption of the system is that people will open the excel file,
fill out the form, link the information to word, then save the FINAL
word file locally or simply print it, and then close both the excel
file and the word file without saving.
However, every once in a while, a user messes up and saves either the
filled out excel file or the filled out word file over the template!
and a restoration of the backup has to be performed.
Now, I am new to VBA, but it seems to me like this should be very
easily preventable, by simply opening the excel file and the word file
without the SAVE AS path pointing to their original locations, I mean
I've seen that behaviour before, where you try to save the file, and
it'll prompt you for a new path that probably starts on your desktop or
something like that. Basically, not giving you the option to press SAVE
and overwrite the original templates.
Notice that the files on the server are readOnly, but the saving over
still happens.
the code below is how the Word file is instantiated from within the VBA
code:
'Contains the name and path of the associated contract template
Const csFilename As String = "---absoluteServerPathtoFile---"
'Retrieve a word application instance if possible, else create one
On Error Resume Next
Set wd = GetObject(, "word.application")
If Err.Number <> 0 Then
Err.Clear ' Clear Err object in case error occured.
Set wd = CreateObject("word.application")
End If
'Open the template file
wd.documents.Open csFilename
Any input is appreciated, I'm sure lots of you out there have enough
experience to tackle this one, and I'm really appreciative if you can
share you knowledge with the rest of us,
Thanx alot in advance,
Sincerely,
Mjd
I'm new to VBA, but it seems quite powerful sometimes. We have a
system, where the user browses to a folder on the server, and opens his
choice of excel file. In this excel file, there is a form, with some
VBA in the background, where one can fill out the form and press a
control button in the excel file, which will place the gathered
information in the excel into a word template with the same name. This
word template exists in the same folder as the excel files.
The assumption of the system is that people will open the excel file,
fill out the form, link the information to word, then save the FINAL
word file locally or simply print it, and then close both the excel
file and the word file without saving.
However, every once in a while, a user messes up and saves either the
filled out excel file or the filled out word file over the template!
and a restoration of the backup has to be performed.
Now, I am new to VBA, but it seems to me like this should be very
easily preventable, by simply opening the excel file and the word file
without the SAVE AS path pointing to their original locations, I mean
I've seen that behaviour before, where you try to save the file, and
it'll prompt you for a new path that probably starts on your desktop or
something like that. Basically, not giving you the option to press SAVE
and overwrite the original templates.
Notice that the files on the server are readOnly, but the saving over
still happens.
the code below is how the Word file is instantiated from within the VBA
code:
'Contains the name and path of the associated contract template
Const csFilename As String = "---absoluteServerPathtoFile---"
'Retrieve a word application instance if possible, else create one
On Error Resume Next
Set wd = GetObject(, "word.application")
If Err.Number <> 0 Then
Err.Clear ' Clear Err object in case error occured.
Set wd = CreateObject("word.application")
End If
'Open the template file
wd.documents.Open csFilename
Any input is appreciated, I'm sure lots of you out there have enough
experience to tackle this one, and I'm really appreciative if you can
share you knowledge with the rest of us,
Thanx alot in advance,
Sincerely,
Mjd