Open and write word file with VB

  • Hi,
    i want to working with VB for this action:
    1. open word file or pdf with VB.
    2. write to word file with VB.
    3. work with VB table that i can change the field, insert Image or write to them.

    in he same time somebody know if i can with word macro to use with one code to point to multy object from the same type(use index i to call the object that i need to call in VB i can put index[image(i)])

  • Re: Open and write word file with VB

    Hi, and Welcome to Ozgrid

    I've written a few macros that create a Word file and writes to it from Excel. I won't be at a computer with a copy of any for several hours, but will post an exemple then that will help with a few of your questions.

    One thing to keep in mind is that when doing this from inside Excel, you need to use Excel VBA syntax when working with the Excel file and Word VBA syntax (often the same but not always ... e.g., Excel does not have paragraphs, Word does not have rows and Columns to reference). Recording macros in Word and looking at the syntax can help keep things straight for using it in the Excel macro.

    Now if I can just remember to post the example as promised when I get home.

  • Re: Open and write word file with VB

    Hi Dennis,
    for the pdf file. i can not make a command button that go to the file(pdf) and open it? i know that in VB i have icon that open a specific pdf file.

  • Re: Open and write word file with VB


    I misunderstood what You meant by "open" ;)

    Here is a solution that open a PDF-file:

    Option Explicit

    Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long

    Sub Open_PDF()
    ShellExecute 0, "open", "c:\OzGrid.pdf", "", "", 1
    End Sub

  • Re: Open and write word file with VB

    Dennis Hi, :rock:
    u can recommend me a good book for VB.
    book that explain how to open files and to read or write to them data.
    also i u have usufull codes that u can give me i appreciate if u can send me meantime until i buying a good book.

  • Re: Open and write word file with VB

    There exist a bunch of Excel-books that cover many things about Excel BUT little about automation of other softwares (open and write date etc). In fact, this is a field which is rarely covered at all in books. Mainly because it does not explicit target the software itself.

    I'm one of "them" who regular manipulate data in other fileformats through automation and therefore You find some stuff on my English site, in the Advanced Excel forum here at OzGrid. BTW, check out the tip of fully automate Office via VB 6.0, which include Excel, Word and Outlook.

    Post Your questions here and I'm totally convinced that You will get a better knowledge and understanding of the answers then buying a book that only give You 5 pages about automation.

    Bob Philips (aka xld) recently post a minor tutorial about early & late binding which You may find useful:

    Edit: Here You find a good source for the Windows API ShellExecute:…b4/html/msdn_shelexec.asp

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!