Results 1 to 10 of 10
  1. #1
    3 Star Lounger
    Join Date
    Apr 2003
    Location
    Calgary, Alberta
    Posts
    208
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow

    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 Settings\Trish\Application Data\Microsoft\Word\STARTUP\TLMUser.dot" _
    , Destination:= _
    "C:\Documents and Settings\Trish\Application Data\Microsoft\Templates\Normal.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

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    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

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    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
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    [quote name='tkrokosh' post='776672' date='24-May-2009 05:17']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.[/quote]
    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.

  5. #5
    3 Star Lounger
    Join Date
    Apr 2003
    Location
    Calgary, Alberta
    Posts
    208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='Andrew Lockton' post='776677' date='24-May-2009 01:05']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
    [/quote]

    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...

  6. #6
    3 Star Lounger
    Join Date
    Apr 2003
    Location
    Calgary, Alberta
    Posts
    208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='StuartR' post='776686' date='24-May-2009 03:25']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.[/quote]

    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

  7. #7
    3 Star Lounger
    Join Date
    Apr 2003
    Location
    Calgary, Alberta
    Posts
    208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='Gary Frieder' post='776676' date='24-May-2009 00:56']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[/quote]

    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!

  8. #8
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    [quote name='tkrokosh' post='776719' date='24-May-2009 17:56']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[/quote]
    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

  9. #9
    3 Star Lounger
    Join Date
    Apr 2003
    Location
    Calgary, Alberta
    Posts
    208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='Andrew Lockton' post='776677' date='24-May-2009 01:05']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
    [/quote]

    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.

  10. #10
    3 Star Lounger
    Join Date
    Apr 2003
    Location
    Calgary, Alberta
    Posts
    208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='StuartR' post='776735' date='24-May-2009 15:16']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
    [/quote]


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

Posting Permissions

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