• Application.OrganizerCopy

    Author
    Topic
    #460055

    It’s been a while since I have had to write VBA, but I’m really struggling with this one. My client requires custom styles to be added to the Normal.dot so that every document created will contain these styles. Originally I created a Normal.dot with all the customization and was going to distribute to this specific set of users (legal dept in big o&g co); however, their IT department has disapproved of a customized normal.dot – due to the fact that they use a Document Mgmnt system that inflates the normal.dot and it needs to be deleted on a regular basis.

    So, I thought I would put all the customization into a User.dot file and put it in the start-up folder – that way any toolbars/macros that I have customized will be available to the user. The problem is making the styles (with keybindings) and autotext available. My current thought is to create a macro with a toolbar button that will copy these commands to the Normal.dot and, if the normal.dot is deleted due to inflation/corruption, it will be easy to train staff to click on a button to add these items back to the normal.dot so they exist for each new document being created. I have researched/tested the Application.OrganizerCopy for both Styles and AutoText but I receive a run-time error 4149. Also, it appears as though I have to create a separate entry for each style/autotex item – I would prefer for this to not to be hard-coded so that the macro doesn’t need updating if new styles/autotext are added to the user.dot in the future. Also, will the code accept %username% instead of an ‘actual’ username? I have used the same code to copy the two autotext entries and added all the keybindings via code.

    [codebox] Application.OrganizerCopy Source:= _
    “C:Documents and SettingsTrishApplication DataMicrosoftWordSTARTUPTLMUser.dot” _
    , Destination:= _
    “C:Documents and SettingsTrishApplication DataMicrosoftTemplatesNormal.dot” _
    , Name:=”Normal”, Object:=wdOrganizerObjectStyles
    [/codebox]

    I have fiddled with the following code for copying the styles (with keybindings) to the ActiveDocument; however, this code is creating a second occurence of the User.dot toolbar (I’m assumming one is stored in the active document as well as the add-in)??? Not sure why the toolbar is being copied?? I’m unsure of how to perform this by copying to the NormalTemplate… ?

    [codebox] With ActiveDocument
    .UpdateStylesOnOpen = True
    .AttachedTemplate = “TLMUser.dot”
    End With
    With ActiveDocument
    .UpdateStylesOnOpen = False
    .AttachedTemplate = “TLMUser.dot”
    End With
    [/codebox]

    I would greatly appreciate any suggestions any of you may have in this regard. Thanx… trish

    Viewing 2 reply threads
    Author
    Replies
    • #1161880

      Trish,

      Hopefully someone here has implemented something like what you’re trying to achieve, and can give specific code advice for this problem.

      But something that doesn’t seem clear here: if your client’s IT department forbids your providing a customized Normal.dot, why are they permitting you to put a global template in the startup directory, that contains code that customizes Normal.dot?! – isn’t that doing the same thing they don’t want you to do, just through much more complicated and unreliable means? Wouldn’t it be much more reliable to avoid the complicated code, and just permit you to do the customizations you want to Normal.dot, manually?

      Another angle on this is: why not just leave Normal.dot alone, and produce an alternative “Blank” or “House Style” template that would be the default for all new documents created at the client? This could contain the custom styles, autotexts, etc., while leaving Normal.dot untouched.

      Gary

      • #1161905

        Trish,

        Hopefully someone here has implemented something like what you’re trying to achieve, and can give specific code advice for this problem.

        But something that doesn’t seem clear here: if your client’s IT department forbids your providing a customized Normal.dot, why are they permitting you to put a global template in the startup directory, that contains code that customizes Normal.dot?! – isn’t that doing the same thing they don’t want you to do, just through much more complicated and unreliable means? Wouldn’t it be much more reliable to avoid the complicated code, and just permit you to do the customizations you want to Normal.dot, manually?

        Another angle on this is: why not just leave Normal.dot alone, and produce an alternative “Blank” or “House Style” template that would be the default for all new documents created at the client? This could contain the custom styles, autotexts, etc., while leaving Normal.dot untouched.

        Gary

        The company wants to decrease the amount of support required for this one department. The helpdesk tends to delete normal.dot files for ‘any’ issues word may be having… it’s crazy… most of the time it’s not the normal.dot, but a corrupt document, lack of knowledge of the software, or the user changing options. Since this customization will only be distributed to approx 60 people out of >1000 in the office, and at the rate the helpdesk deletes the normal.dot, it would would be very hard for everyone to remember that these 60 individuals have a ‘different’ normal.dot than the rest of the company. I would love to be able to distribute the normal.dot and not have to figure this out…

        I did think about creating a template that would include all the customization that they could base all new documents on; however, I’m pretty sure this would be too many ‘steps’ to get the customization and most people would not even bother.

        So here I am broken hearted… trying to figure out a good automated alternative. Thanx for making suggestions and clarifying the reasoning. Have a great day!

    • #1161881

      I would use the application settings for your file paths

      Code:
      With Application
       .OrganizerCopy Source:= .StartupPath & "TLMUser.dot", _
      	Destination:= Options.DefaultFilePath(wdUserTemplatePath) & "Normal.dot", _
      	Name:="Normal", Object:=wdOrganizerObjectStyles
      End With

      Your other code would work equally as well and could be shortened to

      Code:
      With ActiveDocument
        .UpdateStylesOnOpen = False
        .AttachedTemplate = "TLMUser.dot"
        .RefreshStyles
      End With
      • #1161903

        I would use the application settings for your file paths

        Code:
        With Application
         .OrganizerCopy Source:= .StartupPath & "TLMUser.dot", _
        	Destination:= Options.DefaultFilePath(wdUserTemplatePath) & "Normal.dot", _
        	Name:="Normal", Object:=wdOrganizerObjectStyles
        End With

        Your other code would work equally as well and could be shortened to

        Code:
        With ActiveDocument
          .UpdateStylesOnOpen = False
          .AttachedTemplate = "TLMUser.dot"
          .RefreshStyles
        End With

        Thanx for the help in better stating the code in both cases. Is there a way to loop the OrganizerCopy command to collect ALL styles in the user.dot so that I do not have to reference each style/autotext – more may be added in the future.

        Also, with the second code… is there a way to make this code work updating the Normal.dot?

        Thanx in advance for your assistance…

      • #1161962

        I would use the application settings for your file paths

        Code:
        With Application
         .OrganizerCopy Source:= .StartupPath & "TLMUser.dot", _
        	Destination:= Options.DefaultFilePath(wdUserTemplatePath) & "Normal.dot", _
        	Name:="Normal", Object:=wdOrganizerObjectStyles
        End With

        Your other code would work equally as well and could be shortened to

        Code:
        With ActiveDocument
          .UpdateStylesOnOpen = False
          .AttachedTemplate = "TLMUser.dot"
          .RefreshStyles
        End With

        Hi Andrew, thanx very much for the help with the code. In case other’s view this article, the OrganizerCopy code requires (wdUserTemplatesPath) – the ‘s’ was missing after template.

        I changed the second set of code to your shortened method and now I’m receiving an Error 438 – when I debug it’s stopping on .RefreshStyles – I can’t find anything on this code and Word but did find references to Excel. **Update** My memory came back for a moment and I remembered UpdateStyles… this worked. Once again, anyone referring please use .UpdateStyles instead of .RefreshStyles.

        Also, this code is still inserting the TLMUser.dot toolbar into the active document – very unsure why this is happening ??? Any ideas. **Update** As I plug away at this, I finally figured out that it was copying styles from a TLMUser.dot that was temporarily being stored under the Templates folder. I have deleted this old file. I would have thought that .AttachedTemplate would have referenced the StartUp Folder – any quick thoughts on how I should change this line to the Startup path?

        Also, one last thing… is it possible to loop through the OrganizerCopy code at all? As I am a contractor, I may not be around in the future to add a new style that is required.

    • #1161885

      My current thought is to create a macro with a toolbar button that will copy these commands to the Normal.dot and, if the normal.dot is deleted due to inflation/corruption, it will be easy to train staff to click on a button to add these items back to the normal.dot so they exist for each new document being created.

      You could automate this even further by having code in User.Dot that checks to see if the required styles are in Normal.dot, and initiates the copy if needed. Then you wouldn’t need the toolbar button and the training.

      • #1161904

        You could automate this even further by having code in User.Dot that checks to see if the required styles are in Normal.dot, and initiates the copy if needed. Then you wouldn’t need the toolbar button and the training.

        I’m assuming you are suggesting that I put some code into an AutoOpen macro? Could you give me a little more information on how to perform this? Thanx so much… trish

        • #1161916

          I’m assuming you are suggesting that I put some code into an AutoOpen macro? Could you give me a little more information on how to perform this? Thanx so much… trish

          I was thinking of putting code like this in AutoExec. This checks whether one of your unique styles exists in Normal.Dot, if not then you can call the procedure you already have to copy the styles.

          Code:
          	 Sub checknormal()
          	  Dim doc As Document
          	  Dim sty As Style
          	  Dim blFound As Boolean
          	  Const strCheck As String = "Private Style"   ' Name of a style in customized normal.dot
          	  
          		  blFound = False
          		  On Error GoTo ErrorHandler
          		  Set doc = Application.NormalTemplate.OpenAsDocument
          				
          		  For Each sty In doc.Styles
          			  If sty.NameLocal = strCheck Then 
          				  blFound = True
          				  Exit For
          			 End If
          		 Next sty
          				
          		  ' If not blFound then  ' call the procedure that updates normal.dot here
          				
          	  ErrorHandlerExit:
          		On Error GoTo 0
          		doc.Close SaveChanges:=False
          		Set doc = Nothing
          		Exit Sub
          		
          	ErrorHandler:
          		MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
          		Resume ErrorHandlerExit
          	
          	End Sub
          • #1161964

            I was thinking of putting code like this in AutoExec. This checks whether one of your unique styles exists in Normal.Dot, if not then you can call the procedure you already have to copy the styles.

            Code:
            	 Sub checknormal()
            	  Dim doc As Document
            	  Dim sty As Style
            	  Dim blFound As Boolean
            	  Const strCheck As String = "Private Style"   ' Name of a style in customized normal.dot
            	  
            		  blFound = False
            		  On Error GoTo ErrorHandler
            		  Set doc = Application.NormalTemplate.OpenAsDocument
            				
            		  For Each sty In doc.Styles
            			  If sty.NameLocal = strCheck Then 
            				  blFound = True
            				  Exit For
            			 End If
            		 Next sty
            				
            		  ' If not blFound then  ' call the procedure that updates normal.dot here
            				
            	  ErrorHandlerExit:
            		On Error GoTo 0
            		doc.Close SaveChanges:=False
            		Set doc = Nothing
            		Exit Sub
            		
            	ErrorHandler:
            		MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
            		Resume ErrorHandlerExit
            	
            	End Sub

            Thanx so much for this suggestion Stuart… I will ask the client if this will be suitable… have a great day… trish

    Viewing 2 reply threads
    Reply To: Application.OrganizerCopy

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: