+ Reply to Thread
Results 1 to 10 of 10

VBA required to convert WORD to PDF for folders & subfolders

  1. #1
    Registered User
    Join Date
    12-12-2017
    Location
    india
    MS-Off Ver
    2013
    Posts
    29

    VBA required to convert WORD to PDF for folders & subfolders

    Hi Friends,
    i have a task to convert lot of word file to PDF files , i found some code which does the convertion correctly but its not happening for the Subfolders inside the folder
    coud someone helpme to fix it.

    HTML Code: 
    Option Explicit
    
    Sub Word_To_PDF()
    
    Application.ScreenUpdating = False
    Application.DisplayStatusBar = True
    Dim sh As Worksheet
    Set sh = ThisWorkbook.Sheets("Sheet1")
    
    Dim fso As New FileSystemObject
    Dim fo As Folder
    Dim f As File
    
    Dim wb As Workbook
    Dim n As Integer
    
    Dim wordapp As New Word.Application
    Dim worddoc As Word.Document
    
    Set fo = fso.GetFolder(sh.Range("E13").Value)
    
    For Each f In fo.Files
    n = n + 1
    Application.StatusBar = "Processing..." & n & "/" & fo.Files.Count
    
    Set worddoc = wordapp.Documents.Open(f.Path)
    
    worddoc.ExportAsFixedFormat sh.Range("E14").Value & Application.PathSeparator & VBA.Replace(f.Name, ".docx", ".pdf"), wdExportFormatPDF
    worddoc.Close False
    Next
    
    Application.StatusBar = ""
    MsgBox "Process Completed"
    
    End Sub
    Thanks in Advance.

  2. #2
    Registered User
    Join Date
    12-12-2017
    Location
    india
    MS-Off Ver
    2013
    Posts
    29

    Re: VBA required to convert WORD to PDF for folders & subfolders

    could someone in forum, please help me to complete the scripting

    Thanks in Advance

  3. #3
    Forum Guru macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,434

    Re: VBA required to convert WORD to PDF for folders & subfolders

    Cross-posted at: https://www.excelguru.ca/forums/show...its-subfolders
    Please read Excel Forum's Cross-Posting policy in rule 8: http://www.excelforum.com/forum-rule...rum-rules.html

    In any event, why are you even bothering with Excel, since everything you're doing concerns only Word? For example, running the following 'CreateDocPDFs' macro allows you to choose the top folder and have it and all its sub-folders processed, without going anywhere near Excel:
    Please Login or Register  to view this content.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 2000/3/7/10/13/16
    Posts
    49,593

    Re: VBA required to convert WORD to PDF for folders & subfolders

    It has been noted that you often post the same question on multiple sites, without providing a link to where else you have posted. This is a breach of our rules and probably also the rules of the other sites as well, and will not be tolerated. If this trend continues, your membership here will be revoked and you will face a ban.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Registered User
    Join Date
    12-12-2017
    Location
    india
    MS-Off Ver
    2013
    Posts
    29

    Re: VBA required to convert WORD to PDF for folders & subfolders

    Quote Originally Posted by FDibbins View Post
    It has been noted that you often post the same question on multiple sites, without providing a link to where else you have posted. This is a breach of our rules and probably also the rules of the other sites as well, and will not be tolerated. If this trend continues, your membership here will be revoked and you will face a ban.
    Hi FDibbins,
    i m extremely sorry for the cross-posting, i understand the rules of forum, i will make sure it will not happen again from me
    sorry again

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 2000/3/7/10/13/16
    Posts
    49,593

    Re: VBA required to convert WORD to PDF for folders & subfolders

    Thanks for your understanding

  7. #7
    Registered User
    Join Date
    12-12-2017
    Location
    india
    MS-Off Ver
    2013
    Posts
    29

    Re: VBA required to convert WORD to PDF for folders & subfolders

    Quote Originally Posted by macropod View Post
    Cross-posted at: https://www.excelguru.ca/forums/show...its-subfolders
    Please read Excel Forum's Cross-Posting policy in rule 8: http://www.excelforum.com/forum-rule...rum-rules.html

    In any event, why are you even bothering with Excel, since everything you're doing concerns only Word? For example, running the following 'CreateDocPDFs' macro allows you to choose the top folder and have it and all its sub-folders processed, without going anywhere near Excel:
    Please Login or Register  to view this content.

    Thank you Macropod, it worked very well.
    sorry for the late reply

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

    Re: VBA required to convert WORD to PDF for folders & subfolders

    Alternative code:

    Please Login or Register  to view this content.
    Last edited by snb; 06-07-2020 at 07:38 AM.



  9. #9
    Forum Guru macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,434

    Re: VBA required to convert WORD to PDF for folders & subfolders

    Quote Originally Posted by snb View Post
    Alternative code:
    And what makes you think the OP is only concerned with docx files (for which "WordBasic.DisableAutoMacros True" is totally redundant) and that there could never be any mailmerge main documents in the folders?

    Moreover, given the as-usual cryptic nature of your code, perhaps the OP should pay particular attention to your 'Avoid using VBA-code you do not understand' sig line...

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

    Re: VBA required to convert WORD to PDF for folders & subfolders

    Did you really read this thread's title ?

    Are your feelings being hurt ?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. macro to folders and subfolders
    By max_max in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 03-02-2017, 04:38 PM
  2. [SOLVED] creating folders and subfolders
    By Lohara005 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-13-2015, 07:28 AM
  3. Create folders in all the subfolders and move subfolders
    By Amarjeet Singh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-24-2015, 12:51 PM
  4. [SOLVED] VBA code to add folders and subfolders
    By rhlittau in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-25-2013, 06:57 PM
  5. [SOLVED] Creating Folders and Subfolders
    By matt1133 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-15-2013, 03:52 AM
  6. Listing folders and subfolders
    By brokenbiscuits in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 11-11-2011, 08:49 AM

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