From: SW Monkey on
Mr. Who wrote:
> A simple FileExists call should ensure that you don't overwrite a
> pre-existing file. Only a few additional lines of code.


I want the user to be allowed to overwrite the file, I just want them
to be notified that a file exist already.

Do you know the code I can use for this?


Like I said, the macro does this in SW 2004, but not in SW 2005.

Im also trying to figure out how to open the PDF after it is generated.
This would allow the user to verify everything looks good.

From: Mr. Who on
Just before the save add something like this (make sure you add
reference to microsoft scripting runtime)

Dim fso As object
Dim file as object
set fso = createobject("Scripting.FileSytemObject")

if FileExists(PathToWhereFileWillBeSaved) = True Then
msgbox "I'm going to overwrite this file."
Set File = PathToWhereFileWillBeSaved
File.Delete
if FileExists(PathToWhereFileWillBeSaved) = True Then msgbox
"oops i couldnt delete the file. It must be open already or
something."
End if

From: SW Monkey on

Mr. Who wrote:
> Just before the save add something like this (make sure you add
> reference to microsoft scripting runtime)
>
> Dim fso As object
> Dim file as object
> set fso = createobject("Scripting.FileSytemObject")
>
> if FileExists(PathToWhereFileWillBeSaved) = True Then
> msgbox "I'm going to overwrite this file."
> Set File = PathToWhereFileWillBeSaved
> File.Delete
> if FileExists(PathToWhereFileWillBeSaved) = True Then msgbox
> "oops i couldnt delete the file. It must be open already or
> something."
> End if

Mr Who,

I cant get the above to work with my macro posted above. (I added a
reference to MS scripting runtime)

From: Mr. Who on
That was just the code outline. The actual working code would be like
this.

FileName = "C:\temp\myFile.pdf"
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(FileName) = True Then
MsgBox "I'm going to overwrite: " & FileName
Set file = fso.GetFile(FileName)
file.Delete
If fso.FileExists(FileName) = True Then MsgBox "oops i couldnt
delete the file. It must be open already or something."
End If

In terms of integrating it with your existing macro you have to call it
just before Drawing.SaveAs3 FileName, swSaveAsCurrentVersion,
swSaveAsOptions. I am assuming that FileName is the full path to the
PDF file. I can't actually test this with your code because your code
is dependent on the presence of a userform. Anyone else following this
thread should take note that you can't cut and paste the monkey code
and have it work on your system.

From: SW Monkey on

Mr. Who wrote:
> That was just the code outline. The actual working code would be like
> this.
>
> FileName = "C:\temp\myFile.pdf"
> Set fso = CreateObject("Scripting.FileSystemObject")
> If fso.FileExists(FileName) = True Then
> MsgBox "I'm going to overwrite: " & FileName
> Set file = fso.GetFile(FileName)
> file.Delete
> If fso.FileExists(FileName) = True Then MsgBox "oops i couldnt
> delete the file. It must be open already or something."
> End If
>
> In terms of integrating it with your existing macro you have to call it
> just before Drawing.SaveAs3 FileName, swSaveAsCurrentVersion,
> swSaveAsOptions. I am assuming that FileName is the full path to the
> PDF file. I can't actually test this with your code because your code
> is dependent on the presence of a userform. Anyone else following this
> thread should take note that you can't cut and paste the monkey code
> and have it work on your system.

Thanks :)
Thats odd. It seems to work just fine now. I did the same thing you
posted, changed "PathToWhereFileWillBeSaved" to "Filename".

I also removed this line
FileName = "C:\temp\myFile.pdf"
Since I already had a variable called Filename.

It seems to work fine now. Is it bad that I am using a form to store
the filename?

LOL @ the "monkey code" comment.

First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5
Prev: Free IGES Viewer?????
Next: Installation Problem