+ Reply to Thread
Results 1 to 3 of 3

Disable AutoMacros in Word Doc and delete all text files

Hybrid View

abousetta Disable AutoMacros in Word... 06-26-2010, 12:56 AM
snb Re: Disable AutoMacros in... 06-26-2010, 06:11 AM
abousetta Re: Disable AutoMacros in... 06-27-2010, 03:03 AM
  1. #1
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Post Disable AutoMacros in Word Doc and delete all text files

    Hi everyone,

    I have been putting together a macro that opens a word document --> saves only data for forms as text file. I have two issues that I can't seem to understand:

    1) The following code works fine when I select all word docs in a folder using the msoFileDialogFolderPicker but not when I choose only one file using GetOpenFilename.

    WdApp.WdBasic.DisableAutoMacros 1
    WdApp.Documents.Open WdName
    The error states that the Word document is protected, but this is the case in both cases above. Its the same file so why it is giving me an error only when I use the GetOpenFilename method and is there a way to circumvent this issue.


    2) I want to delete all the created text files that were generated during the process but my maco won't work.

    Sub KillTxtFiles()
    
    Dim TxtName     As String
    Dim sFPath      As String
    
        With Application.FileDialog(msoFileDialogFolderPicker)
            .AllowMultiSelect = False
            .Show
            If .SelectedItems.Count > 0 Then sFPath = .SelectedItems(1) & "\"
        End With
    
    ' Can't get the macro to delte the text files in a given folder
        TxtName = Dir$(sFPath & "*.txt")
          Do Until TxtName = ""
            Kill (TxtName)
            TxtName = Dir()
          Loop
    
    End Sub
    Does anyone see what is wrong with it

    Thanks in advance.

    abousetta
    Last edited by abousetta; 06-27-2010 at 03:04 AM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Disable AutoMacros in Word Doc and delete all text files

    This is sufficient
    Kill sFPath & "*.txt"

  3. #3
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Disable AutoMacros in Word Doc and delete all text files

    Thanks snb. This does the trick.

    As for the file protection, I have added code to unprotect the file regardless of whether an error message appears or not. This seems to be working for now, but I have to test it further.

    abousetta

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1