vba

unclefink

Registered User.
Local time
Today, 14:08
Joined
May 7, 2012
Messages
184
I've got a macro that converts five separate reports to .pdf files and saves them to a specific folder on the desktop for later use via button in a form. These .pdf reports are intended to be used for reference on a portable device in the field. What I am trying to do is create a single button that will update these reports by deleting the existing .pdf files in the specific folder and then save them again as an updated report.

Right now when I click the button and if the reports already exist i get a prompt that says these reports already exist do you want to save over them. I have to do this or every report to be replaced.

What i want it to do is delete the existing files in the folder and then save them. The folder is exclusive to these reports so there are no other files present.

I found this link that gave some direction; however it doesn't seem to be working when I change the file location. Can someone give me some insite on this process or assist me with understanding the process noted in this link.

http://word.mvps.org/faqs/macrosvba/DeleteFiles.htm

The files are not "read only" so there is no need to change that portion.

To delete all the files in a given directory:
Code:
'Loop through all the files in the directory by using Dir$ function
Dim  MyFile  As String
MyFile = Dir$("C:\Users\name\Desktop\test\*.*")
 Do While  MyFile <> ""
    KillProperly "C:\Users\name\Desktop\test" & MyFile
    'need to specify full path again because a file was deleted 1
    MyFile = Dir$("C:\Users\name\Desktop\test\*.*")
 Loop


After saving the form with this code behind the button I get a pop up that says compile error: sub or function not defined


What am i missing?


Thanks in advance..
 
do you have the KillProperly function from that link in your code?
 
This part
KillProperly "C:\Users\name\Desktop\test" & MyFile
should be
KillProperly "C:\Users\name\Desktop\test\" & MyFile
 
I have the above noted code behind a button right now, I made the change indicated by Mihail and its still giving me the same error. Any suggestions.
 
Last edited:
You missing this routine (I have founded in the link you provided)

Code:
Public Sub  KillProperly(Killfile  As String)
    If Len(Dir$(Killfile)) > 0  Then
        SetAttr KillFile, vbNormal
        Kill KillFile
    End If
 End Sub
 

Users who are viewing this thread

Back
Top Bottom