dcsimg
Results 1 to 5 of 5

Thread: Word via VB6 Automation, Attaching Template Causes Error

  1. #1

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,622

    Word via VB6 Automation, Attaching Template Causes Error

    Argh, Microsoft and their updates are driving me bonkers.

    This is a new one since the latest Windows 10 update.

    I'll often start a new Word document with a template (either .DOT or .DOTX file). However, I'd rather my new document wasn't "attached" to this template, as the template itself only has a temporary existence. Therefore, every time I start a new document, after I get its "doc" (Documents) variable created, I execute this code:

    Code:
    
    Public Sub WordSetTemplate(docToSet As Object)
        ' This keeps it from being attached to the original template.
        ' Not sure why but setting the template sometimes errors.
        On Error Resume Next
            docToSet.AttachedTemplate = "Normal"
        On Error GoTo 0
    End Sub
    
    Now, I've got a comment in there that it sometimes has an error. But it's worse than that now. I'm now (since the last Win10 update) consistently getting this error (from Word's VBA) when VB6 executes this code:

    Name:  vbaerror.png
Views: 196
Size:  4.6 KB

    If anyone has any knowledge/experience with this, knowing about it would be greatly appreciated.

    Thanks In Advance,
    Elroy

    EDIT1: Just as some more FYI, these templates do not have any VBA macros in them. In fact, nowhere do I use Word templates with macros, and I've tried it in several places with several different templates, and I'm now consistently getting this error.

    EDIT2: I'm running Windows 10 64-bit, Version 1709 (OS Build 16299, 192)
    Last edited by Elroy; Jan 10th, 2018 at 05:20 PM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  2. #2
    Frenzied Member
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    1,188

    Re: Word via VB6 Automation, Attaching Template Causes Error

    If you haven't seen these already (may be an FM20.dll permissions/access issue):

    https://social.msdn.microsoft.com/Fo...oad?forum=vsto

    https://social.msdn.microsoft.com/Fo...forum=exceldev

  3. #3

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,622

    Re: Word via VB6 Automation, Attaching Template Causes Error

    Hi jdc2000,

    Interesting links. Regarding FM20.dll, I haven't had anything to do with that thing in years. Any/all OCX/DLL things I use are standard OCX files. It's easy to give a list because I use them as SxS. Here they are: mscomctl.ocx, mscomct2.ocx, msflxgrd.ocx, richtx32.ocx, & tabctl32.ocx. In addition to those, I have references to the DAO and the ADO. However, I'm fairly certain that none of those has anything to do with Office Automation (at least not as I'm using it).

    Also, I have found a work-around, and possibly identified the "problem". The Normal.dotx on my development computer has macros in it. However, none of my Word templates for this application have any macros in them. I suppose, Microsoft has decided that swapping out the template, from one without macros to one with macros via automation, is a security risk. Actually, I suppose I can see that. But it doesn't really make all that much sense. I mean, I'm already running a program (giving me access to anything I want). I certainly wouldn't need to swap out some Word template to do something nefarious.

    But hey ho, I've got a fix. I'm going to create a blank .DOTX file (with no macros), set it in a folder, and use this for my "universal" template. I've already tried it, and it solves the problem. It's just annoying.

    Best Regards,
    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  4. #4
    Frenzied Member
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    1,188

    Re: Word via VB6 Automation, Attaching Template Causes Error

    Thanks for the update.

    I saw something similar to that today when I was testing a macro. I created a new blank workbook, saved it as .xlsx, created a macro, deleted it, and then when I tried to re-save it, I got a warning that it would be saved without macros unless I changed it to .xlsm - but the macro had already been deleted.

  5. #5

    Thread Starter
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    4,622

    Re: Word via VB6 Automation, Attaching Template Causes Error

    You know, I'd be much happier if trying to change the template just resulted in a VB6 error. Probably 95% of my users will be using a "Normal" template that doesn't contain macros. In those cases, I'd prefer to use that template. However, if they've got one (like me) that does contain macros, then I could redirect to my just created Blank.dotx as the template. The way things stand, I've got no choice but to use the Blank.dotx template to make sure that I don't get that error in post #1 (the little form capture).
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width