Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

How To Create New Doc From My Template

The following code only opens the template:

Dim wrd As Word.Application
Set wrd = New Word.Application
wrd.Documents.Open docTemplate

I want to create a new document from this template.

How to?

Thanx in advance.

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Create Template
How can I make a form into a template so that the user can
make multiple copies and save each one to a different file
with the open "c: etc."

Create New Workbook From Template
I have an .xlt file called "Reports.xlt". My plan was to write a sub that will update a cell in all worksheets in the project with the date that the user chooses and create a new .xls workbook without affecting the template. With help from daniel_donoghue I was able to accomplish this, the code is below.
As you will see I am using the SaveAs method to create the new monthly report without loosing the template. The problem is that the custom button that calls the sub changes to the path name of the new file, for example:


Open Reports.xlt
Click custom button to run sub (assigned to Reports.XLT!NewReport)
Sub Creates a new file J:MyDirMyFolderAugust2005Report.xls
Close all files
Open Reports.xlt
Custom button to run sub now re-assigned (J:MyDirMyFolderAugust2005Report.xls!NewReport)

This only becomes a problem after the reports for 2005 are archived and no longer exist in the directory.

My Question: Is there a better way than SaveAs to create a new file where the custom button assignment won't be changed, and even better that won't copy the VBA code along with it?

I hope this has been enough info. if not please let me know, I can really use the help.

Thank you in advance.


Private Sub cmdNewMonth_Click()
Dim mDate As String
Dim yDate As String
Dim ws As Worksheet

mDate = cmbMonth.Text
yDate = Format(Date, "yyyy")

For Each ws In Worksheets
Sheets(ws.Name).Range("A2") = mDate
Sheets(ws.Name).Range("A3") = Sheets(ws.Name).Name & " for " & mDate & " " & yDate
Next ws

ThisWorkbook.SaveAs "J:MyDirMyFolder" & mDate & "Report", xlWorkbookNormal
Unload Me

End Sub

Private Sub UserForm_Initialize()
Dim sMonth As String
Dim i As Integer
For i = 1 To 12
sMonth = Format(DateValue(i & "/1/1"), "mmmm")
cmbMonth.AddItem sMonth
Next i
cmbMonth.Text = Format(Date, "mmmm")

End Sub

Create Document From A Template
I have this code which works but I want to expand on it.

Private Sub Print_Template()
Dim objWord As Object
'Set objWord = Word.Application
Dim strFileName As String
Set objWord = CreateObject("Word.Application")
strFileName = "invoice1.doc"

With objWord
.Documents.Open (App.Path & "")
.ActiveDocument.SaveAs (App.Path & "" & strFileName)
End With
Set objWord = Nothing

Exit Sub
ErrorCode = Err.Number
ErrorDesc = Err.Description
MsgBox Str(ErrorCode) + ErrorDesc
Resume Next
End Sub

What I want to do is put data into the document at bookmarks. I have these bookmarks set in the .dot already. Can anyone point me to an example? Thanks.

Also should the objWord.Quit statement be inside the With?

How To: Create A Doc From A Word Template
Hi guys, i'm sure this is simple but i spend to enough time, i have to ask. I have a procedure that opens a word template, makes some changes a shows it to the user. The thing is, that it's the template that actually opens, so if the user save changes, the next time it executes, the document will show old data plus the new changes.

How can i do to create q new doc based on the template? (whitout opening the template)

Heres the code i'm using right now:

VB Code:
Public Sub SendToWord(ID As Integer)DoEvents 'someone tell me to put this, but i have no idea what it doesDim wordApp As ObjectDim wordDoc As ObjectDim wordRng As ObjectDim Cot As clsCotizaciones, xCot As clsCotizaciones_ItemsDim Cli As clsClientes, Productos As clsProductosDim C As Byte Set Productos = New clsProductosSet Cot = New clsCotizacionesSet Cli = New clsClientes If Not Cot.GetReg(ID) Then Exit SubIf Not Cli.GetReg(Cot.IDCLIENTE) Then Exit Sub Set wordApp = CreateObject("Word.Application")wordApp.Documents.Open FileName:=App.PATH & ""Set wordDoc = wordApp.ActiveDocumentSet wordRng = wordDoc.Content 'IDwordRng.Find.Execute FindText:="COTIZACIÓN  #", _                     ReplaceWith:="COTIZACIÓN  #" & Str(Cot.ID), _                     Wrap:=1                     'FechawordRng.Find.Execute FindText:="Fecha de cotización:", _                     ReplaceWith:="Fecha de cotización: " & Cot.FECHA, _                     Wrap:=1 'ContactowordRng.Find.Execute FindText:="Contacto:", _                     ReplaceWith:="Contacto: " & Cli.CONTACTO_NOMBRE & " " & Cli.CONTACTO_APELLIDO, _                     Wrap:=1 'Razon SocialwordRng.Find.Execute FindText:="Cotizar a:", _                     ReplaceWith:="Cotizar a: " & Cli.RAZONSOCIAL, _                     Wrap:=1 'Observación:wordRng.Find.Execute FindText:="Observación: ", Wrap:=1If wordRng.Find.found Then    wordRng.MoveStart Unit:=4, Count:=1    wordRng.InsertAfter vbCrLf & vbCrLf & Cot.NOTAS    wordRng.Font.Name = "Arial"End If  C = 2 For Each xCot In Cot.ITEMS    If C > 2 Then wordDoc.Tables.Item(1).Rows.Add        wordDoc.Tables(1).Cell(Row:=C, Column:=1).Range.Delete    wordDoc.Tables(1).Cell(Row:=C, Column:=1).Range.InsertAfter Text:=Productos.GetField(xCot.IDPRODUCTO, "NOMBRE")        wordDoc.Tables(1).Cell(Row:=C, Column:=2).Range.Delete    wordDoc.Tables(1).Cell(Row:=C, Column:=2).Range.InsertAfter Text:=for_sig(xCot.PRECIO_NETO, xCot.DOLAR_FLAG, 4)        wordDoc.Tables(1).Cell(Row:=C, Column:=3).Range.Delete    wordDoc.Tables(1).Cell(Row:=C, Column:=3).Range.InsertAfter Text:=CStr(xCot.CANTIDAD)        wordDoc.Tables(1).Cell(Row:=C, Column:=4).Range.Delete    wordDoc.Tables(1).Cell(Row:=C, Column:=4).Range.InsertAfter Text:=for_sig(xCot.PRECIO_NETO * xCot.CANTIDAD, xCot.DOLAR_FLAG, 4)        wordDoc.Tables(1).Cell(Row:=C, Column:=5).Range.Delete    wordDoc.Tables(1).Cell(Row:=C, Column:=5).Range.InsertAfter Text:=Productos.GetField(xCot.IDPRODUCTO, "ENTREGA")     C = C + 1Next wordApp.Visible = True Set wordApp = NothingSet wordDoc = NothingSet wordRng = NothingSet Cot = NothingSet Cli = NothingSet xCot = NothingSet Productos = Nothing End Sub

well, thanks!


Using Access Template To Create DBs In VB 6 Help
I am knew to VB. I would like to create a VB program that uses an Access database containing several tables as a template (no data) that can copy and save the database as another database dynamically. The new databases need to be independant of each other. The new databases, created once a year, are to be then modified (data added)through the VB program.The program would be a standalone program to run on a single machine as a desktop application. Does anyone have any suggestions as to the best approach to this?

Create Wbook From Template....
I have a master wbook and a template wbook.

Is possible to:

 Filtre for each value from column A (4500, 4501, 4502 ecc...) of master wbook (sheet a.t. camania), copy the active cells filtred and copy into wbook template and save the new wbook into c:mydir4500_15112005...

... in effect to the and of cicling of copy in c:mydir hre is the scenario....



Edited by - sal21 on 11/15/2005 5:09:18 AM

Advice: Create An Access Template?
Hey Guys & Gals,

Thanks for all the great help I received on this forum.

I'm starting an Access project and I need advice.
Weekly, I will read a deliminated file into Access (give it a new filename) and have a set of queries always run against it.

Should I create a template to accomplish this? or an Add-In?
Know any good links on how to create Access templates?

Thanks, L.A.

Using A .dot Template - How To Create Multiple Pages Within The Same Document?

The background is that I have a .dot template which I use for printing Address labels, using merge fields which I fill from a VB6 Application. There are 21 labels on a page, so when the 22nd one is reached, the code creates a new Word document based on the .dot template.

Is there any way I can contain this in the one document, i.e. when the 22nd label is reached, a new page will be opened in the document which will have the same fields as the 1st page???

I've tried searching around but can't find any Method in the Word object, I thought there would be something along the lines of a .NewPage

Any help would be greatly appreciated,


P.S. If anyone needs to see the code for what I'm doing let me know

Create New Word Doc Based On Custom Template
Good morning all,

I am trying (and trying and trying) to create a new word document based on a custom template that I created. I have looked everywhere I can think but can't piece together all of the information. If the document already existed no problem, plenty of examples for that!!!

I have an access database to use for a mail merge. I set up templates with the field code and need to use this as the basis of creating a new doc.

Any thoughts, ideas, suggestions??


Create A Visual Basic Report Template
I am currently doing a report template
which serial numbers are increasing by day
ex day 1, 1 , 2, 3
day 2, 4, 5, 6
and the user has to key in the headers
the last serial will be stored in an access db.
The output(report template) will be stored in a word document.

I am having problems with the formating part of document
ex header ,footer, page number and how to generate this report template with the click of a button
"generate report"

Open Word Template, Create New Document
How do i open a word template and create a new document from it?

There's like 20 parameters when opening a word.application,,,,,,...... Mark P.
Providing Low Cost Powerful Point of Sale Solutions.

Blocking Template After Exporting From Access 2002 To A Word Template
I am having some difficulty determining the appropriate code for stopping a template from popping up after I close the document to which my Access data has been transferred to. My VB code automatically saves the document, but when I quit Word, my original template pops up. Whatever code I insert into VBE doesn't seem to stop it. I hope someone can help me.... Here's the relevant portion of the code below:

'Creates a Word instance to use for the 8D form. Uses the existing
'Word instance if there is one; otherwise, creates a new instance.
Set objWord = GetObject(, "Word.Application")
If Err.Number = 429 Then
'Word isn't running; creating a Word object.
Set objWord = CreateObject("Word.Application")
End If

On Error GoTo Command126_ClickError

strDocsPath = "V:QCProblem Cases" & ""
strSaveName = "BWA CAR No. " & Me![Customer Tracking Number] & ".doc"
strSaveNamePath = strDocsPath & strSaveName
strTemplatePath = "V:QCProblem Cases" & ""
strWordTemplate = strTemplatePath & ""

'Check for existence of template in template folder,
'and exit if not found
strTestFile = Nz(Dir(strWordTemplate))
If strTestFile = "" Then
MsgBox strWordTemplate & " template not found; can't create 8D form"
Exit Sub
End If

Set objDocs = objWord.Documents
objDocs.Add strWordTemplate
.( I have removed the section which relates fields between Access and the template...there's nothing that controls opening and closing of the document)
With objWord
.Visible = True
Debug.Print "Going to save as " & strSaveName
.ActiveDocument.SaveAs strSaveName
.Selection.EndKey Unit:=wdStory
End With

Exit Sub

MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume Command126_ClickExit

End Sub

I would appreciate if I receive a reply ASAP (job-related!!)

How To Paste On A Word Template Without Loosing The Formatting Of The Template?
I'm new on VB please help me!
I have to fill some special word template with informations caming from an access DB.
Here the code I'm using now.

Private Sub SearchAndReplaceOnce(monDocWord As Word.Document, strTagARemplacer As String)

Dim maPlage As Variant
Set maPlage = monDocWord.Content

With maPlage.Find
.Execute FindText:=strTagARemplacer
If .found = True Then maPlage.Paste
End With
End Sub

All this code is working but the method Paste is replacing also the formatting that I have pre-defined on the word template.
How can I do to avoid this problem?

Word Object To Save Template As A Template.
I use a word object to open a template and resave it to template.
The reason I'm opening the template is that I want to run a macro that fills the template with data from bookmarks.

I use this code:

Dim objWordApp As Object
Set objWordApp = CreateObject("Word.Application")
objWordApp.Documents.Add Template:=TemplatePath, NewTemplate:=True
objWordApp.ActiveDocument.LoadMe sConn, FunctionId, sFunctionType, SupplierId
objWordApp.ActiveDocument.SaveAs FileName:=WorkPath & FileName
objWordApp.ActiveDocument.Close SaveChanges:=wdSaveChanges

But when opening the new template I get this annoying reference to the old template. The old macros doesn't save in the new template.

When running save as in word on a template the macros are transferred to the new file without referencing to the old macro.

How do you do this in VB?

Create Wbook From TEMPLATE Wbook
Assuming i have template.xls in c: est
I open wbook MASTER_INPS.xls.
Into thi wbook MASTER_INPS.xls is present a sheet TABELLA.
Into column A of TABELLA are present many value.

Is possible to filtre based TABELLA column A, the value into column A of A.T. CAMPANIA, after the copy entire range filtred from A.T. CAMPANIA sheet save in c: est the realted TEMPLATE with: name=name of criteria filtred for example: 4500_&date_of_system similarr 4500_14112005.xls

Cicling this creation of new wbook for eache value into TABELLA

Opening A Template As A Template

I am trying to open a excel template file (.xlt) as the template rather than as a new document (.xls)

the code i am using is as follows, but i cannot find the necessary code elements to make it open as a an xlt file.

Any thoughts greatly appreciated.


P.S. Newbie with some VBA experience

Template Help
ok i have a template that i can pull up it is linked to a database that when i hit a button to print labels it does the search though the database and places the results in the database that the template is using. now the template is opened , but it opens with the merge info meaning <<first name>> in stead of the kenneth, but if i hit the show merged databutton it shows them all right <<abc>>, how can i make the template open already merged like when i hit the buttob
i am using vb6 and word from office xp
here is some of the code

If Text1.Text = "" Then
Exit Sub
End If

Dim var_add As String


If InStr(1, var_add, Text1.Text, vbTextCompare) > 0 Then
End If

Dim objwdApp As Object
Dim objWdDoc As Object
Dim objwdRange As Object

Set objwdApp = CreateObject("Word.Application")

'Add new document
Set objWdDoc = objwdApp.Documents.Open(FileName:="C:LABEL_TEMPLATE1.DOT")

objwdApp.Visible = True

ok thats it please help
thanks in advance

Is there a way to email a WORD template through Outlook multiple times without it losing its reference to the template?

Dll Template
i got vb 2005 express and it didnt come w/ a dll template project so if any1 can be give me 1 tha would be appreciated and how to add it thanks

Help With A Template From VB6
I'm really newbie to VB and would like to know what to do with this error i get. Ok I start a new project, add ...Microsoft Visual StudioVB98TemplateFormsWeb Browser.frm
to my project. I added the reference: Microsoft internet control. I try to execute the program and I get this: "No MDI Form available to load"

What's the problem? I need help...

Thanks alot

Knowledge is the rule

DAT And Template
I have a couple of questions to ask. How would I create a template file in Visual Basic to arrange text in a certain way into a richtext box? and also, how would I create a DAT file so that the information could go through the template and into the textbox but not be read by opening the DAT file in "Notepad" or "MS Word".

HI ya,

How do i open a new word document in VB using my own template.
I have a template and when I click a command button
i should open a new word document with that template.

Please provide code.


Relatively New To C++... A Little Template Help?

template<class T>
void square(T x)
return(x * x);

void main()
char letter = 'A';
int integer= 5;
double money= 2.25;
cout<<"The square of "<<letter<<" is "<<square(letter)<<endl;
cout<<"The square of "<<integer<<" is "<<square(integer)<<endl;
cout<<"The square of "<<money<<" is "<<square(money)<<endl;

I receive the error:

error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion)

on each of my cout statements.

Thanks in advance!

I'm trying to send a mass email out, the field are taken from a table a populated into a ???? i would like to know what is the best way to populate the fiedls into, if i need to create a letter template. Should i use world and then attached the world document to the email or should i create a report using visual basic or is there any other way to do it. Im looking for a fast and easy way to do it

OCR With Template

We need scan certain parts from an A4 document (landscape), and put the data in a CSV-file.
Some of it is printed, some is handwritten.
We only need the data from certain boxes on the document.

Does anybody have experience with any (commercial or freeware) OCR-software which has some kind of template which I can put over the scanned document so that only the needed data is picked?



Open Template
Hi everyone,

I'm trying to open a new document based on a template that I created from VB6.
My template is in the 'User Templates' folder for MS Word.
The only way I was able to do that is by creating a dummy doc based on my template, opening that doc, then opening AttachedTemplate, closing dummy doc. This kind of works, but there's got to be a shorter way to open the template.

Thanks for your help.

Template In Word
Hello all,

I am trying to sort out a template in Word which will set up a template for a
letter - I want it to work so that a box pops up and you type the
address of the recipient in, and the same for other bits in the text of
the letter- and these are then put in the right place on the page. Any
ideas how to do it ?

I know some VB so a push in the direction would be more than helpful.


Template Question

I use visual basic to fill in variables ( eg {variable} ) in a word document that I use as a template for an order form.

I can fill in regular variables like {company_name} thats no problem.
I am having difficulty with arrays. for example: {#order_product}, {#order_quantity}, {#order_price} (# means that it is an array)

How do I set sections in word?
Imagine I want a result similar to:

** the template before parsing **

{#customer_name} {#customer/order_product} {#customer/order_quantity} {#customer/order_price}
** the template after parsing **

OsMo Monitor 1 500
Graphical Card 1 300
CPU 1 250
MKosLof Cooler 1 50
Harddrive 1 250
I would do this with a table in word, but the template engine does not need to know that (for all it knows it will be done with tabs), all layout stays in the template.
How can I set sections then? As you can see there are 2 loops here, one that goes through all the customers and one that goes through all ordered items of that customer.

How can I do these loops without screwing up the layout?

I dont know if I am explaining this correctly, please tell me if my question is too obscure.

I hope someone can help me.



How Do I Add A Template To A Word 03 Doc?
what is a templates extension?

what would be the code to add a saved template into a word doc and if possible add it at a certain area like the end of the doc


and i have searched i couldnt find any code for adding a template

VBA Crashing My Template
I have a Word template in which I have placed some VBA code. When executed, the template does create a new document -- as it should. However, Word crashes before any of the code is run (I have a msgbox command as the first line in the Document_New & Document_Open routines which never appears). Instead I just get the "Microsoft Word has encounted a problem and needs to close." message. It seemed to have worked fine until I added an InputBox in the code (which is supposed to run right after the Msgbox command).

Any ideas??

Thanks in advance.

Releasing A Template
i have this app which typists use to open audio files and a suitable template however these templates must be kept on a network drive so that they can be modified by administrators. problem i'm having is that if another typist starts using the template, when the program is ended it dosn't release the template cleanly, i have tried using FileCopy but this fails if the template is already in use. take a look at this code and suggest changes.


Public Sub Command1_Click()
File2.Path = "z:Template" & Text1.Text

'find proper template
getdoc = File2.Path & "" & File2.FileName

'chop filename to suit convention
fullname = Text2.Text
sfilename = fullname
x = UCase(Right(fullname, 3))
'checks for extension
Call findextension(x)
'takes input from user

pathtosaveto = "z:Temp Files" & myname & "Temp file" & sfilename & ".doc"
Set objwdApp = CreateObject("word.application")
If File2.FileName = "" Then
Set objwdDoc = objwdApp.Documents.Add()
Set objwdDoc = objwdApp.Documents.Open(FileName:=getdoc)
'(I would like it to release the template (getdoc) at this point if possible.)
End If
objwdApp.ActiveDocument.SaveAs FileName:=pathtosaveto
objwdApp.Visible = True

WindowState = 1

End Sub
the application(word) is released at the end of the process

Template Question

I have made a template class that uses word documents to replace variables between { and }. It works great, but I wonder if this is also possible:

In the word document there is an excel sheet, and in that excel sheet there are also variables between { and }. I want to replace those by the real values like in my word template, how do I do that?
I have to be able to detect if one or more excel sheets are present in the word document.

Thank you very much!

Word Template

I was wondering if the following is possible:

I have several word templates in a folder
In my (vb 6) project I let the user choose which templates he wants to edit (by a checkbox)
[Now my question:]
I want to open all checked templates in 1 new word document (like you open en copy the content of the selected templates in a new word document)

How do I do that? (sample code is greatly appreciated)

Big thanks in advance!!

VB6 And Word Template
I have an ascii text database that is a fixed length type, I created a user type to access the db, I created a "template" in Word for a mass mail letter. I can access the records information in the db and pass it to the word template. The problem is - when I get to the next record and pass the information (ie: name) it will add it to the same page and name filed in the word document. I need to add a page with the same text and fields from the original template, then add the new record info, go on to the next record and repeat until finished adding as many pages as needed.

Example of what shows in the word document after just 2 records are selected.

Dear John Smith Betty Crocker of 123 Main Street 432 South Street
Here is what we show for your current City and State - City1,ST City2,St2

I need it to read:

Dear John Smith of 123 Main Street
Here is what we show for your current City and State - City1,ST

<end of page>
<new page>
Dear Betty Crocker of 432 South Street
Here is what we show for your current City and State - City2,St2
<end of page>

(Without the <end of page> <new page> of course

Any help would be greatly appreciated - Thanks

Adding A Template
i've a little problem.
im trying to open a document and add a template.
But in vba mode ( code)
By doing this i also want to set some properties like automatically update document styles etc.
Just no idea. anyone can help me please.

Writing To A Template
hi, i need to write some info in the bookmarks of a template. how do i do this?
maybe using a template is not the best way to write to pre-formated document. (?)

any help will be appreciated.

Template Party Mix
I've done a template that open a form when the user dblclick on a field. The problem is that when the document attached to is open and an other document attached with an other template (ex. with is open at the same time, I dblclick on the Document Attached to and try to open the form on the document Attached with And then ERROR!

Is there a way to keep the event listening (WindowBeforeDoubleClick) listen only for the documents attached with

Using Template In MS Words For VB
Hi all,

I have create a template in MS Word for my VB app but I am confuse right now. My objective in the app is to allow users to create their own letters thru the template that I provide, since I can open the template thru VB; the only problem that I do not know how to fix is... how to save the typed docs from my app into a new file?

Using An Excel Template
I'm having an issue using an Excel Template to compile a report with VB. My code opens a read-only excel file, and fills in the cells with the reporting information. It works perfectly -- the first time you run it. However, if the Sub is run a second time, and the user still has the original Excel sheet open, it does not work properly. What happens in this case is that the template will open a second time, but since the first file is still open, the cells on this sheet are changed, and the newly opened template is left blank. Here is my code:

Private Sub cmdSubmit_Click()

Dim xlApp As Excel.Application

Set xlApp = New Excel.Application

xlApp.Workbooks.Open FileName:="U:Test.xls"
xlApp.Visible = True

'Code to Change Cells Here'

End Sub

I think what I'm missing is a command after I change the cells that "unlinks" the VB app from the excel file.

Any Ideas?

How To Recognize A Template Without It's Name...
Hi all...

I have a template which I am distributing among several machines in a network. Now i need to identify the template even if someone renames it.

Is it possible to get information about a template by storing some info in it, like a version number or author name etc....

Thanx in advance
vikram db

Word Template
I have to create more than 3000 word documents, based on a template, using visual basic.

for i = 1 to 3000
Set WordDoc = m_WordApp.Documents.Add("")

It takes a lot of time to create the document, so I would like to know if there is a way to use a template which would be in memory instead of loading it from the disk.

I already tried WordDoc.AttachedTemplate without success.

Could someone help me ?

Word Template
I have a program that opens a Word template and inserts certain information into bookmarks on the Word document.

Dim objWord As Word.Application
Set objWord = New Word.Application

'Open SubmittalData coverpage and import data
Documents.Open FileName:="P:Submittal"

How do you open a new document based on the template instead of opening the actual template? I don't want the users to be able to accidentally change the template.

Template Bloat
With reference to a template in MS Word: Anyone know of a GOOD way to get rid of "Template Bloat"?

I have tried exporting the module that I have, then saving the template, then importing the module back, compiling the project, then saving it again. Sometimes it helps a little but not much.

Template CustomDocumentProperties
Does anybody know a way of accessing a template's custom properties without actually opening the template (or a document based on the template)? Maybe through FileSystemObject coding or similar?


Word Template Help
need to create an email template that takes the content(+ header and footer) and send it to lotus notes and allows the user to email someone with the entire look of the original document

Template No Found
i am using vb6.0 and access as database. i am using MSWord for reporting. I have a project "Pathology Lab" in vb98 folder of visual basic. In that folder there is templates folder in which i placed the different templates used for reporting. Here is my code

<Private Sub cmdDoc_Click()
Dim wordapp As Word.Application
Dim thisdoc As Document
Dim thisrange As Range
Set wordapp = CreateObject("word.application")
If wordapp Is Nothing Then
MsgBox "could notstart word"
End If

wordapp.Documents.Open App.Path & "Pathology lab">

this code generates Run time error '5273':
file could not found.
All the pathway is correct and file is present in the folder. What is wrong with this code.

Word Template
I'm creating a Template word document as like:
However, once the template is saved & closed, the next time it is opened it still requests macro's to be enabled due to the reference to the original .dot file,

Is it possible to remove this link in the VBA code of the original document once complete, or prevent word from requesting for macros?

Get Template Path
I have a template file,, which some users need to double click when they want a new document based on this template (sound normal so far).

On the new sub there is going to be some code which imports a few txt file into the document. These txt files are located in the same folder as the .dot file.

My question is this: I do not want to place the .dot file at a default location (users will be free to put the dot and its txt files anywhere) but when the new document is created 'activedocument.path' is not usefull for getting the path prefix to import the txt files. Is there a way to resolve the templatedocuments path??

Created From Template Or Not?
Is there any way, within an Excel VBA Module, to tell whether the file has been created as a new workbook from the original template, or whether it's already been saved as it's own file and re-opened that way?

In other words - I have set up a template. When a user creates a new file from that template, I want to have a userform automatically pop-up. When the user saves the file under it's own filename, and re-opens the file at a later date, the userform will not automatically pop-up.

The only thought I have right now, is to store a value in a cell in the workbook, and have it check for that value. So, if I have a cell set aside to store the value of "Saved" (or whatever I decide to call it, since Saved is a reserved word), and it starts out as false in the template, then I can have it change to true when the user actually saves the workbook.

Does anyone have any better ideas?

Copyright © 2005-08, All rights reserved