URGENT: MSWORD Query

The following function opens a word document

Public Function OpenNewDoc(Optional docname As String, Optional ro As Boolean = False, Optional atrfl As Boolean = False, Optional bVisible As Boolean = True)

    If Len(docname) > 0 Then
        Set wrdDoc = wrdApp.Documents.Open(docname, ReadOnly:=ro, addtorecentfiles:=atrfl)
    Else
        Set wrdDoc = wrdApp.Documents.Add
        wrdDoc.Select
        Set wrdSelection = wrdApp.Selection
    End If

 wrdApp.Visible = bVisible

End Function

What I would like to do, is open a template document, save it with a predefined file name, and then open the document ...

As much as I can I would also like to use the word object itself to do this ...

I am using Word 11.

Regards

DWE
LVL 1
dwe0608Asked:
Who is Participating?
 
bruintjeCommented:
Hello dwe0608,

i assume you want to be able to add that functionality to the part if there is no docname supplied? then you can do this

---------
Public Function OpenNewDoc(Optional docname As String, Optional ro As Boolean = False, Optional atrfl As Boolean = False, Optional bVisible As Boolean = True)
Dim wrdApp As Application
Dim wrdDoc As Document
    If Len(docname) > 0 Then
        Set wrdDoc = wrdApp.Documents.Open(docname, ReadOnly:=ro, addtorecentfiles:=atrfl)
    Else
        Set wrdDoc = wrdApp.Documents.Add(Template:="c:\mytemplate.dot")
        wrdDoc.Select
        Set wrdSelection = wrdApp.Selection
    End If

 wrdApp.Visible = bVisible

End Function
----------

this line

        Set wrdDoc = wrdApp.Documents.Add(Template:="c:\mytemplate.dot")

will open a new document based on the template provided, you can also use something like Template:="c:\mytemplate.doc"

key is that if you leave it empty as in your original it will use the empty normal.dot by default

hope this helps a bit
bruintje
0
 
dwe0608Author Commented:
Yes, it does ....

Is there a definative resource for msword which talks about using vb and msword ?
0
 
bruintjeCommented:
good question, i'm not sure

what i mostly do is using the object browser in the ms office application [F2 in the vb editor]
most of the info i learned from there, if you can make things work in the office app then port it to VB or any other environment

otherwise i google for the thing i need to know, because most of the time its something that should've been done by others already :-)
and use google groups instead of plain google, the group search is really helpful in finding relevant snippets

thanks for the grade

0
 
dwe0608Author Commented:
thanks for the prompt response... I will try those mthods of search ...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.