?
Solved

URGENT: MSWORD Query

Posted on 2006-04-15
4
Medium Priority
?
149 Views
Last Modified: 2011-10-03
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
0
Comment
Question by:dwe0608
  • 2
  • 2
4 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 2000 total points
ID: 16462986
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
 
LVL 1

Author Comment

by:dwe0608
ID: 16463003
Yes, it does ....

Is there a definative resource for msword which talks about using vb and msword ?
0
 
LVL 44

Expert Comment

by:bruintje
ID: 16463024
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
 
LVL 1

Author Comment

by:dwe0608
ID: 16463031
thanks for the prompt response... I will try those mthods of search ...
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question