Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-22-2016, 06:37 AM
Ajay2506 Ajay2506 is offline Programmatically Selecting Files in Word for Windows Windows 7 64bit Programmatically Selecting Files in Word for Windows Office 2013
Novice
Programmatically Selecting Files in Word for Windows
 
Join Date: Jun 2016
Posts: 8
Ajay2506 is on a distinguished road
Default Programmatically Selecting Files in Word for Windows

Is there a way to write a vba code in word file, which allow users to open a browse option to select and open the files in various folders, where they can select any file to open, then do some operation on them and save it.

Similar work has been performed in this site in Excel, but I want it for word file.
https://msdn.microsoft.com/en-us/lib...ffice.14).aspx



So when we click the macro, it will first ask to select the PDF file, once we click open then it will open that pdf file in word, then we can call other macro, perform some action and then save the file with the .docx extension.
Reply With Quote
  #2  
Old 06-22-2016, 07:49 AM
gmayor's Avatar
gmayor gmayor is offline Programmatically Selecting Files in Word for Windows Windows 10 Programmatically Selecting Files in Word for Windows Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Bearing in mind that not all PDF format files are editable in Word, and that this only works for Word versions 2013 and later, the following can be used to select and open one

Code:
Option Explicit

Sub Macro1()
Dim strFname As String
Dim oDoc As Document
    strFname = BrowseForFile("Select the PDF file to open")
    If strFname = vbNullString Then GoTo lbl_Exit
    Set oDoc = Documents.Open(strFname)
    'do stuff with odoc
lbl_Exit:
    Exit Sub
End Sub

Function BrowseForFile(Optional strTitle As String) As String
'Graham Mayor - http://www.gmayor.com
'strTitle is the title of the dialog box
'Set bExcel value to True to filter the dialog to show Excel files
'The default is to show Word files
Dim fDialog As FileDialog
    On Error GoTo err_handler
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    With fDialog
        .Title = strTitle
        .AllowMultiSelect = False
        .Filters.Clear
        .Filters.Add "Adobe PDF files", "*.pdf"
        .InitialView = msoFileDialogViewList
        If .Show <> -1 Then GoTo err_handler:
        BrowseForFile = fDialog.SelectedItems.Item(1)
    End With
lbl_Exit:
    Exit Function
err_handler:
    BrowseForFile = vbNullString
    Resume lbl_Exit
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 06-24-2016, 10:23 AM
Ajay2506 Ajay2506 is offline Programmatically Selecting Files in Word for Windows Windows 7 64bit Programmatically Selecting Files in Word for Windows Office 2013
Novice
Programmatically Selecting Files in Word for Windows
 
Join Date: Jun 2016
Posts: 8
Ajay2506 is on a distinguished road
Default Thank you

Thank you for your help
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Programmatically Selecting Files in Word for Windows How to use the icons for macros included in Word programmatically dherr Word VBA 6 03-27-2015 01:05 AM
word 2003 slow saving passworded files windows 7 dontdoslow Word 5 08-08-2014 04:12 AM
Programmatically Selecting Files in Word for Windows programmatically inserting hidden text into a Word 2010 table epid011 Word VBA 16 12-30-2013 11:29 AM
how to identify the word files created using Windows or Mac Operating System? mariaprabudass Word 0 08-06-2010 05:52 AM
Programmatically get File Path for currently opened WORD document franferns Word 1 11-26-2009 12:36 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:27 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft