Custom Property - what am I doing wrong?

R

Robert_L_Ross

This is driving me crazy! I have a .dot I'm using to create forms that
connect to an Excel spreadsheet (to populate a userform drop down box).

I want to have three custom properties I can use anywhere in the document
(one is for the path to the Excel data source, one is the location to save
the completed forms and one is the location of the document template for
opening new blank forms).

Two of my three custom properties work fine (data source and destination
path). I cannot get the document template location to work. I want to have
these set in one place so if we need to move/copy the form, data source or
change the destination path, all we need to do is change the custom
properties, not the code.

Here's my custom properties:
Name: SourceFile
Type: Text
Value: G:\GS-220\SLATE\CORRECTION_SHEETS\SCHOOL_LIST.xls

Name: TemplateFile
Type: Text
Value: G:\GS-220\SLATE\CORRECTION_SHEETS\Correction_Sheet.dot

Name: CompletedDestination
Type: Text
Value: G:\GS-220\SLATE\CORRECTION_SHEETS\CompletedForms\

The SourceFile and CompletedDestination work fine, but the TemplateFile
gives me a Run-time error 13, Type mismatch.

Here's the code where I call it from:
Sub NEWFORM()

Dim CURRENTDOCNAME As String
CURRENTDOCNAME = ActiveDocument.FullName
Word.Documents.Add ActiveDocument.CustomDocumentProperties("TemplateFile")
Documents(CURRENTDOCNAME).Close

End Sub

Can anyone tell me what it is that I'm doing wrong?!?
 
J

Jonathan West

Robert_L_Ross said:
This is driving me crazy! I have a .dot I'm using to create forms that
connect to an Excel spreadsheet (to populate a userform drop down box).

I want to have three custom properties I can use anywhere in the document
(one is for the path to the Excel data source, one is the location to save
the completed forms and one is the location of the document template for
opening new blank forms).

Two of my three custom properties work fine (data source and destination
path). I cannot get the document template location to work. I want to
have
these set in one place so if we need to move/copy the form, data source or
change the destination path, all we need to do is change the custom
properties, not the code.

Here's my custom properties:
Name: SourceFile
Type: Text
Value: G:\GS-220\SLATE\CORRECTION_SHEETS\SCHOOL_LIST.xls

Name: TemplateFile
Type: Text
Value: G:\GS-220\SLATE\CORRECTION_SHEETS\Correction_Sheet.dot

Name: CompletedDestination
Type: Text
Value: G:\GS-220\SLATE\CORRECTION_SHEETS\CompletedForms\

The SourceFile and CompletedDestination work fine, but the TemplateFile
gives me a Run-time error 13, Type mismatch.

Here's the code where I call it from:
Sub NEWFORM()

Dim CURRENTDOCNAME As String
CURRENTDOCNAME = ActiveDocument.FullName
Word.Documents.Add
ActiveDocument.CustomDocumentProperties("TemplateFile")
Documents(CURRENTDOCNAME).Close

End Sub

Can anyone tell me what it is that I'm doing wrong?!?

Try Documents.Add instead of Word.Documents.Add
 
T

Tony Strazzeri

I want to have three custom properties I can use anywhere in the document
(one is for the path to the Excel data source, one is the location to save
the completed forms and one is the location of the document template for
opening new blank forms).
Name: TemplateFile
Type: Text
Value: G:\GS-220\SLATE\CORRECTION_SHEETS\Correction_Sheet.dot
The SourceFile and CompletedDestination work fine, but the TemplateFile
gives me a Run-time error 13, Type mismatch.

Here's the code where I call it from:
Sub NEWFORM()

Dim CURRENTDOCNAME As String
CURRENTDOCNAME = ActiveDocument.FullName
Word.Documents.Add ActiveDocument.CustomDocumentProperties("TemplateFile")
Documents(CURRENTDOCNAME).Close

End Sub

Hi Robert,
Not sure I understand you correctly. You want to create/store three
document variables inside the activedocument. Is that correct?

The above code does not make clear where the fields are created or
stored. Can you post your complete code?

My comments next to your code may help to make clear what is going
wrong.


Dim CURRENTDOCNAME As String 'define variable
CURRENTDOCNAME = ActiveDocument.FullName 'assign var with the full
path/doc name of the (existing) Activedocument.
 
T

Tony Strazzeri

Please ignore my other reply.

Try
Dim tf As String
tf=ActiveDocument.CustomDocumentProperties("TemplateFile")
Word.Documents.Add tf

Hope this helps.

Cheers
TonyS.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top