Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Saving Word file to disk automatically

Discussion in 'Information Technology' started by Someone, Nov 12, 2005.

  1. Someone

    Someone
    Expand Collapse
    Guest

    Hello

    My database has a facility to auto-generate a Word document for a selected
    record. The OnClick even runs the following module.

    Function WordMerge()
    Dim objWord As Word.Document
    Set objWord = GetObject("C:\Location....\Template_Name.dot",
    "Word.Document")
    objWord.Application.Visible = True
    objWord.MailMerge.OpenDataSource _
    Name:="C:\Location....\db_name.mdb", _
    LinkToSource:=True, _
    Connection:="TABLE tbl_Direction", _
    SQLStatement:="SELECT tbl_Name.field_name, etc, etc, etc, etc FROM
    [tbl_Name] WHERE [tbl_Name.Check] = True"
    objWord.MailMerge.Execute

    With Dialogs(wdDialogFileSaveAs)
    .Name = "C:\Location....\Word_Name.doc"
    .Show
    End With

    End Function

    The With/End With part is me experimenting and I can get the save as
    dialogue box to appear and change the file name. However, I want the file
    to atomically save using a specified filename without prompting / user
    interaction.

    How can I do this?

    Thanks
    M
     
  2. Loading...

    Similar Threads Forum Date
    World Irish lawmakers back bill on life-saving abortions Breaking News Jul 4, 2013
    Heritage Saving Gurdwaras in Pakistan History of Sikhism Feb 20, 2011
    World Naomi Bronstein Lives On - A Humanitarian Accredited With Saving 140,000 Lives Breaking News Jan 23, 2011
    USA U.S. is Saving War Memorials in Iraq Breaking News Jun 3, 2010
    Saving Punjab History of Sikhism Sep 18, 2009

  3. Norman Yuan

    Norman Yuan
    Expand Collapse
    Guest

    Since you have already gotten the Word.Document object in hand, you can
    simply call Word.Document.SaveAs() method.

    You may want to have your function like this:

    Function WordMerge(Optional fileName As String="C:\MyDocs\Myfile.doc")

    'your code
    Dim objWord As Word.Document
    Set objWord =
    GetObject("C:\Location....\Template_Name.dot","Word.Document")
    objWord.Application.Visible = True
    objWord.MailMerge.OpenDataSource _
    Name:="C:\Location....\db_name.mdb", _
    LinkToSource:=True, _
    Connection:="TABLE tbl_Direction", _
    SQLStatement:="SELECT tbl_Name.field_name, etc, etc, etc, etc FROM
    [tbl_Name] WHERE [tbl_Name.Check] = True"
    objWord.MailMerge.Execute

    'Save doc
    objWord.SaveAs fileName
    objWord.Close

    End Function

    "Someone" <someone@somewhere.com> wrote in message
    news:OA$HyWt5FHA.744@TK2MSFTNGP10.phx.gbl...
    > Hello
    >
    > My database has a facility to auto-generate a Word document for a selected
    > record. The OnClick even runs the following module.
    >
    > Function WordMerge()
    > Dim objWord As Word.Document
    > Set objWord = GetObject("C:\Location....\Template_Name.dot",
    > "Word.Document")
    > objWord.Application.Visible = True
    > objWord.MailMerge.OpenDataSource _
    > Name:="C:\Location....\db_name.mdb", _
    > LinkToSource:=True, _
    > Connection:="TABLE tbl_Direction", _
    > SQLStatement:="SELECT tbl_Name.field_name, etc, etc, etc, etc FROM
    > [tbl_Name] WHERE [tbl_Name.Check] = True"
    > objWord.MailMerge.Execute
    >
    > With Dialogs(wdDialogFileSaveAs)
    > .Name = "C:\Location....\Word_Name.doc"
    > .Show
    > End With
    >
    > End Function
    >
    > The With/End With part is me experimenting and I can get the save as
    > dialogue box to appear and change the file name. However, I want the file
    > to atomically save using a specified filename without prompting / user
    > interaction.
    >
    > How can I do this?
    >
    > Thanks
    > M
    >
    >
     
  4. Someone

    Someone
    Expand Collapse
    Guest

    Hi Norman

    Thanks very much for that. This worked.

    Despite this, I decided to choose a different approach and use bookmarks
    instead, as the new security on importing SQL commands on mail merges, plus
    documents being saved with merge fields was not viable, as the resultant
    documents needed to be emailed to 3rd parties. I'm happy with the bookmark
    approach.

    Thanks again for your help.
    M
    "Norman Yuan" <NotReal@NotReal.not> wrote in message
    news:ulys5nt5FHA.1184@TK2MSFTNGP12.phx.gbl...
    > Since you have already gotten the Word.Document object in hand, you can
    > simply call Word.Document.SaveAs() method.
    >
    > You may want to have your function like this:
    >
    > Function WordMerge(Optional fileName As String="C:\MyDocs\Myfile.doc")
    >
    > 'your code
    > Dim objWord As Word.Document
    > Set objWord =
    > GetObject("C:\Location....\Template_Name.dot","Word.Document")
    > objWord.Application.Visible = True
    > objWord.MailMerge.OpenDataSource _
    > Name:="C:\Location....\db_name.mdb", _
    > LinkToSource:=True, _
    > Connection:="TABLE tbl_Direction", _
    > SQLStatement:="SELECT tbl_Name.field_name, etc, etc, etc, etc FROM
    > [tbl_Name] WHERE [tbl_Name.Check] = True"
    > objWord.MailMerge.Execute
    >
    > 'Save doc
    > objWord.SaveAs fileName
    > objWord.Close
    >
    > End Function
    >
    > "Someone" <someone@somewhere.com> wrote in message
    > news:OA$HyWt5FHA.744@TK2MSFTNGP10.phx.gbl...
    >> Hello
    >>
    >> My database has a facility to auto-generate a Word document for a
    >> selected
    >> record. The OnClick even runs the following module.
    >>
    >> Function WordMerge()
    >> Dim objWord As Word.Document
    >> Set objWord = GetObject("C:\Location....\Template_Name.dot",
    >> "Word.Document")
    >> objWord.Application.Visible = True
    >> objWord.MailMerge.OpenDataSource _
    >> Name:="C:\Location....\db_name.mdb", _
    >> LinkToSource:=True, _
    >> Connection:="TABLE tbl_Direction", _
    >> SQLStatement:="SELECT tbl_Name.field_name, etc, etc, etc, etc FROM
    >> [tbl_Name] WHERE [tbl_Name.Check] = True"
    >> objWord.MailMerge.Execute
    >>
    >> With Dialogs(wdDialogFileSaveAs)
    >> .Name = "C:\Location....\Word_Name.doc"
    >> .Show
    >> End With
    >>
    >> End Function
    >>
    >> The With/End With part is me experimenting and I can get the save as
    >> dialogue box to appear and change the file name. However, I want the
    >> file
    >> to atomically save using a specified filename without prompting / user
    >> interaction.
    >>
    >> How can I do this?
    >>
    >> Thanks
    >> M
    >>
    >>

    >
    >
     

Share This Page