Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-11-2013, 01:03 AM
Milon Milon is offline Toggle objects on / off with custom toolbar Mac OS X Toggle objects on / off with custom toolbar Office for Mac 2011
Novice
Toggle objects on / off with custom toolbar
 
Join Date: Jul 2013
Posts: 3
Milon is on a distinguished road
Default Toggle objects on / off with custom toolbar


Hi Forum!

I have been trying for 3 days to find a way to toggle objects (Company Logo and address) that are in the header and footer of a letterhead and invoice. There are other objects (page no's etc) in the header and footer that need to be always visible / printed so I can not just turn the whole header on and off.

The idea is the client can click a button to turn these objects off when they print on their headed paper (Pre-printed). Or leave them on to send a PDF or print a document for internal use.

I have an functioning example document but I can not work out how to target specific objects I import onto the page (or to define a name for them).

The example I have uses this code on an image file ("logo1"):

If ActiveDocument.Sections(1).Headers(wdHeaderFooterF irstPage).Shapes("logo1").Visible = True Then
ActiveDocument.Sections(1).Headers(wdHeaderFooterF irstPage).Shapes("logo1").Visible = False
ActiveDocument.Sections(1).Headers(wdHeaderFooterF irstPage).Shapes("logo2").Visible = False
Else
ActiveDocument.Sections(1).Headers(wdHeaderFooterF irstPage).Shapes("logo1").Visible = True
ActiveDocument.Sections(1).Headers(wdHeaderFooterF irstPage).Shapes("logo2").Visible = True
End If

Any help would be greatly appreciated!
Miles
Reply With Quote
  #2  
Old 07-11-2013, 05:01 PM
gmaxey gmaxey is online now Toggle objects on / off with custom toolbar Windows 7 32bit Toggle objects on / off with custom toolbar Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Miles,

The way I do this is to create two autotext entries. One LH_Logo is the Logo graphic. The other No_Logo is a empty shape of the same size and position as LH_Logo. Then add an autotext field in the first page header:

{AutoText LH_Logo}

Code:
Sub AddLetterhead()
Dim oFld As Field
Dim oRng As Word.Range, oRngFld As Word.Range
Dim lngInterogate As Long
  
  lngInterogate = ActiveDocument.Sections(1).Headers(1).Range.StoryType
  Set oRng = ActiveDocument.StoryRanges(wdFirstPageHeaderStory)
  'Does the header Autotext field exist?
  On Error Resume Next
  If Not oRng.Fields(1).Type = wdFieldAutoText Then
    On Error GoTo 0
    'No, then create it.
    Set oRngFld = oRng.Duplicate
    oRngFld.Collapse wdCollapseStart
    Set oFld = oRng.Fields.Add(oRngFld, wdFieldAutoText, "LH_Logo")
    oFld.Update
    On Error GoTo 0
  Else
   Set oFld = oRng.Fields(1)
    If InStr(oFld.Code.Text, "No_Logo") > 0 Then
      oFld.Code.Text = Replace(oFld.Code, "No_Logo", "LH_Logo")
      oFld.Update
    End If
  End If
lbl_Exit:
  Exit Sub
End Sub
Sub RemoveLetterhead()
Dim oFld As Field
Dim oRng As Word.Range
Dim lngInterogate As Long
  
  lngInterogate = ActiveDocument.Sections(1).Headers(1).Range.StoryType
  Set oRng = ActiveDocument.StoryRanges(wdFirstPageHeaderStory)
  'Does the header Autotext field exist?
  If oRng.Fields.Count > 0 Then
    Set oFld = oRng.Fields(1)
    If oFld.Type = wdFieldAutoText Then
      If InStr(oFld.Code.Text, "LH_Logo") > 0 Then
        oFld.Code.Text = Replace(oFld.Code, "LH_Logo", "No_Logo")
        oFld.Update
      End If
    End If
  End If
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 07-18-2013, 06:11 AM
Milon Milon is offline Toggle objects on / off with custom toolbar Mac OS X Toggle objects on / off with custom toolbar Office for Mac 2011
Novice
Toggle objects on / off with custom toolbar
 
Join Date: Jul 2013
Posts: 3
Milon is on a distinguished road
Default

Dear Greg,

Sorry for not getting back earlier, I have been away... but thanks for your reply, it seems a very good technique, I will certainly give it a go.

I have The windows version with office 2010 now, much easier than my mac version to navigate so this should be fairly straightforward. I will let you know if it works out! Thanks again, Miles
Reply With Quote
  #4  
Old 07-23-2013, 06:21 AM
Milon Milon is offline Toggle objects on / off with custom toolbar Mac OS X Toggle objects on / off with custom toolbar Office for Mac 2011
Novice
Toggle objects on / off with custom toolbar
 
Join Date: Jul 2013
Posts: 3
Milon is on a distinguished road
Default

Dear Greg,
It all seems to be working great so thank you again. I just have one question that I have so far been unable to solve on my own and that is how I apply this to two both my headers and not just the first one. The second header is different as it has page numbers / subject etc. Thanks for any help! Miles
Reply With Quote
Reply

Tags
headers footers all pages, toolbar, vba in microsoft word

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Toggle objects on / off with custom toolbar Convert equation objects to inline objects sumjoh Word VBA 1 01-29-2013 08:38 PM
Quick Parts - Own Custom Toolbar nutrastat Word 3 09-09-2011 01:52 PM
Migrate 2003 custom toolbar to 2007 shameerau Word 0 05-16-2011 07:42 PM
Toggle objects on / off with custom toolbar custom toolbar with buttons to open new docs based on templates Brandi Mail Merge 18 06-15-2010 02:10 PM
Dock a custom floating toolbar? itgoeson PowerPoint 0 05-25-2010 08:34 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:52 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft