Results 1 to 5 of 5

Word - Sharing String Between Subroutines for Kill Statement Directory

Threaded View

  1. #1
    Registered User
    Join Date
    10-15-2018
    Location
    Canberra Australia
    MS-Off Ver
    2010
    Posts
    5

    Word - Sharing String Between Subroutines for Kill Statement Directory

    Hi Guys, Part of my job involves combining dozens of word docs and pdf's into a single PDF. As PDF files combines waaay faster within Adobe pro than word docs I am using a macro to convert all word docs within a folder to pdf (it does this quickly) I then go in afterwards and have to manually delete the word docs... you can see where im going with this.

    I'm very new to this and have Frankenstein'ed code from various places in order to have it delete the word docs after the conversion and would love some advice.

    TL:DR, Requesting your beautiful assistance in deleting only .doc files within a folder using a string from the previous sub as the directory location. My efforts so far pasted below


    Sub Run()
    
    Call ExportWordToPDF
    Call KillDocs
    
    End Sub
    
    Public Sub ExportWordToPDF()
    
    Dim strFilename As String
    Dim strDocName As String
    Dim strpath As String
    Dim oDoc As Document
    Dim fDialog As FileDialog
    Dim intPos As Integer
    
    Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
    With fDialog
        .Title = "Select folder and click OK"
        .AllowMultiSelect = False
        .InitialView = msoFileDialogViewList
        If .Show <> -1 Then
            MsgBox "Cancelled", , "List Folder Contents"
            Exit Sub
        End If
        strpath = fDialog.SelectedItems.Item(1)
        If Right(strpath, 1) <> "\" Then strpath = strpath + "\"
    End With
    If Documents.Count > 0 Then
        Documents.Close SaveChanges:=wdPromptToSaveChanges
    End If
    If Left(strpath, 1) = Chr(34) Then
        strpath = Mid(strpath, 2, Len(strpath) - 2)
    End If
    strFilename = Dir$(strpath & "*.doc")
    
    While Len(strFilename) <> 0
        Set oDoc = Documents.Open(strpath & strFilename)
        strDocName = ActiveDocument.FullName
        intPos = InStrRev(strDocName, ".")
        strDocName = Left(strDocName, intPos - 1)
        strDocName = strDocName & ".pdf"
        oDoc.SaveAs2 FileName:=strDocName, _
            FileFormat:=wdExportFormatPDF, _
            CompatibilityMode:=14
           strFilename = Dir$()
        oDoc.Close SaveChanges:=wdDoNotSaveChanges
        
         Wend
    End Sub
    
    Sub KillDocs()
    
    Kill strpath & "\" & "*" & .doc
    
    MsgBox "Completed"
    End Sub
    Last edited by Leith Ross; 10-16-2018 at 11:24 PM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Grab last word from string and then delete word from original string.
    By mtilbury in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-14-2015, 04:14 AM
  2. vba to search for a word in files in a directory
    By NickyC in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-19-2015, 01:42 AM
  3. [SOLVED] can't debug some subroutines in my project, locked subroutines
    By florin_excel in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-28-2012, 01:16 PM
  4. Parse Directory into String field
    By AppSupportKarl in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-06-2012, 12:40 PM
  5. Find current directory - Optional string
    By Jacques Grobler in forum Excel General
    Replies: 3
    Last Post: 10-03-2011, 01:31 AM
  6. [SOLVED] Kill Command - Using directory from workbook cell
    By superfurry in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-22-2010, 02:12 PM
  7. Sharing variables between Excel and Word
    By Berny in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-31-2006, 09:35 AM

Tags for this Thread

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