Results 1 to 13 of 13
  1. #1
    Lounger
    Join Date
    Aug 2003
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    2 problems : Macros (Word 2000/ Word 97)

    Hi All,

    Preamble:
    I have a Word Template which has macros embedded in it. When you bring up the template it prompts user with questions and upon clicking the Ok button, in the code I am creating another document and modifying it depending on the choices the user made.

    Here is the code i am using to create the document ...
    Options.DefaultFilePath(wdDocumentsPath) = "c:" - save the file to the hard drive
    Options.DefaultOpenFormat = wdOpenFormatDocument - Open in Word format
    Application.DefaultSaveFormat = ""
    ActiveDocument.SaveAs FileName:="test.doc"

    Ok now, with my problems...
    1. After all processing is done, when I go open test.doc it is still of type "DOCUMENT TEMPLATE" and not a WOrd DOCUMENT as i would like it <img src=/S/bwaaah.gif border=0 alt=bwaaah width=123 height=15> ..... How do I save a template as a Word Document... what am i doing wrong?

    2. I want to disable the macros in the "test.doc" .. What code should i use to do the same ?

    Thanks in advance...

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: 2 problems : Macros (Word 2000/ Word 97)

    1. I don't think it is a good idea to open a template, then save it as a document. A template has a different internal structure than a document. Why don't you create a new document based on the template:

    Documents.Add Template:="MyTemplate.dot"

    2. If you create a document based on a template, the macros from the template will be available, but they won't be stored in the document. If you don't want the macros to be available at all, why base the document on the template? Base it on Normal.dot, or on a custom blank template.

  3. #3
    Lounger
    Join Date
    Aug 2003
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 2 problems : Macros (Word 2000/ Word 97)

    I dont want to macros to be available after the document has been created as i dont want the user( who is very very lets say picky and inquisitive ) to mess with the macros in the document. Is there a way to disable macros thru code in a document ( in the scenario i described in my first post)

    Thanks,

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: 2 problems : Macros (Word 2000/ Word 97)

    The easiest way is

    1) Not storing macros in the document (only in a template).
    2) Breaking the link between document and template after the document has been created, by attaching Normal:

    ActiveDocument.AttachedTemplate = "Normal"

  5. #5
    Lounger
    Join Date
    Aug 2003
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 2 problems : Macros (Word 2000/ Word 97)

    ActiveDocument.AttachedTemplate = "Normal" : Works well in Word 2000, but when i try to run the same in Word 97 it gives me a runtime error : 4198 [img]/forums/images/smilies/sad.gif[/img]

    Need more help!!!!!!!!!!!!!!!!!!!!!

    thanks,

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: 2 problems : Macros (Word 2000/ Word 97)

    Does ActiveDocument.AttachedTemplate = "Normal.dot" work in Word 97?

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: 2 problems : Macros (Word 2000/ Word 97)

    Try this, while resolves any problem with Word finding the template in its path:

    ActiveDocument.AttachedTemplate = NormalTemplate

    Also, make sure the correct document is active. I prefer to use a specific Document object to avoid ambiguity:

    Dim docNew as Document
    Set docNew = Documents.Add(Template:=my template)
    docNew.AttachedTemplate = NormalTemplate

    I've only tested this in Word 2002, but unless AttachedTemplate was read-only in Word 97, in which case you might have to use an old WordBasic method, it should still work.

  8. #8
    Lounger
    Join Date
    Aug 2003
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 2 problems : Macros (Word 2000/ Word 97)

    Ok here is my real problem...The template works great when it is run by itself(standalone).. But when i try to run it remotely as a template, it croaks at the ActiveDocument.AttachedTemplate= NormalTemplate... Says Run Time Error...

    This is how i am running it remotely :
    "path of the winword.exe" -t "name of my template"

    Thanks,

  9. #9
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: 2 problems : Macros (Word 2000/ Word 97)

    Does the new document really need to be based on your template? If you can make all the modifications you need through code, then you could just base it on Normal.dot in the first place (i.e., leave the Template:= parameter off of the Documents.Add method call).

    Otherwise, I don't understand why you would get that error. I assume you tried the second approach I posted above.

  10. #10
    Lounger
    Join Date
    Aug 2003
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 2 problems : Macros (Word 2000/ Word 97)

    I have a test.dot file that has macros in it. This test.dot file has all the bookmarks for my final document. The test.dot file also has all the user interface( questions on UserForms, answers to which determine what bookmarks will be populated with data from a local database and which bookmarks will be deleted etc... ). SO, after the user is done making his choices, he clicks an Ok button. in the Ok buttonclick script, i am trying to make a copy of the template (since it has all my bookmarks etc) and create a Word Document(final.doc) MINUS the macros etc..
    Once created the final.doc file is a plain Word document to the user. Like i mentioned in my earlier post, ActiveDocument.AttachedTemplate= NormalTemplate works fine when I run it standalone. But since this test.dot is on the WAN, an user who accesses this template should be able to create a final.doc file and be able to use it as a Word Document.
    So, to be able to run it on teh WAN, the command is "path of teh winword.exe" -t "test.dot". When i run teh copy on the WAN, it says Runtime error 4198, Command failed. at the ActiveDocument.AttachedTemplate= NormalTemplate line..
    Following is part of the code in the btn_Ok_Click()
    Options.DefaultFilePath(wdDocumentsPath) = "c:"
    Options.DefaultOpenFormat = wdOpenFormatDocument
    Application.DefaultSaveFormat = ""
    ActiveDocument.SaveAs FileName:="final.doc"
    ActiveDocument.AttachedTemplate = NormalTemplate
    So help me please.. I hope i did not confuse you further <img src=/S/beep.gif border=0 alt=beep width=15 height=15>

    Thanks,

  11. #11
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: 2 problems : Macros (Word 2000/ Word 97)

    The template is on a slow WAN link, and you are saving a document to the local disk. Maybe a timing problem. If you put a MsgBox "Click OK to proceed" between the .SaveAs and the .AttachedTemplate lines, allowing Word to "settle down" a bit before changing the template, does it help?

    Other thank bookmarks, which you could replicate into a new blank document by copying and pasting from your working document, what else is in the template that you need?

  12. #12
    Lounger
    Join Date
    Aug 2003
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 2 problems : Macros (Word 2000/ Word 97)

    In myy final document, i only need to replicate the bookmarks... How do i go about this? As you can see, I am trying to save the template (using save as ) as a document (by attaching the Normaltemplate) so that way my final.doc will only have the bookmarks and the data that i replace the bookmarks with. All this works well when i run it locally (i.e when i double click the .dot file), but if i try to run it from teh windows STart menu using teh run command "winword.exe" "test.dot" it does not work. What am i doing WRONG Thanks for all the help...

  13. #13
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: 2 problems : Macros (Word 2000/ Word 97)

    I don't know what's going wrong. Please see my previous post for (1) a diagnostic suggestion, and (2) an alternative approach (create a blank document, copy and paste the bookmarks from the body of the template into the blank document).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •