+ Post New Thread
Results 1 to 5 of 5
Office Software Thread, VBA Puzzle in Technical; I'm using a VBA for Word macro that creates a series of shapes inside the headers and footers of the ...
  1. #1

    Join Date
    Jan 2012
    Location
    Seattle, WA
    Posts
    4
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    VBA Puzzle

    I'm using a VBA for Word macro that creates a series of shapes inside the headers and footers of the document. The last one that I create is a line shape in the header of page two. After the creation of this shape, I'd like to get back into the main document and continue on from there but I can't seem to make it happen. I get an error message that says, "This method or property is not available because the current selection is not in a header or footer." However, the shape is created in the header, so I don't understand why I'm getting this error message.

    Here's the code I'm using :

    'Create the shape and set it's properties
    .Headers(wdHeaderFooterPrimary).Shapes.AddShape msoLine, 50, 40, 500, 1
    ActiveDocument.Sections(1).Headers(wdHeaderFooterF irstPage).Shapes(4).Select 'Select the shape
    'Set the shape's properties
    Selection.ShapeRange.Line.ForeColor = RGB(0, 0, 0) 'change line color to black
    Selection.ShapeRange.Shadow.Type = msoShadow6

    'Get back into the main document
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

    I've tried deselecting the shape in order to select the paragraph mark inside the header and I still get the same error message.

    I'm stumped. Any advice or help is greatly appreciated!

  2. #2

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,697
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Like this?

    Code:
         Dim Section As Long
         Section = 1
    
         With ActiveDocument.Sections(Section).Headers(wdHeaderFooterPrimary)
             .Shapes.AddShape msoShapeRegularPentagon, 10, 10, 100, 100, .Range
         End With
         
        ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    Draws single shape in header, then goes to the main page for whatever else you're adding in.

    I feel you're missing something from what you've shown us in the code above in terms of even getting that part to work, but see if what I mean is right (Works in 2007 at least)

    Steve

  3. #3

    Join Date
    Jan 2012
    Location
    Seattle, WA
    Posts
    4
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Hi Steve, thank you for responding. I'm using Word 2010 if that means anything.

    You are right about the code I posted. It is edited for simplicity and just show the trouble spot. The part where I create and format the shape is within a With/End With statement. In fact it is the fourth shape that I create - two on page one and then two on page two (including the line in the header of page two). They are all created fine but when it tries to execute the line:

    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

    I get the error, "This method or property is not available because the current selection is not in a header or footer." Which doesn't make sense, of course, since the blasted line was created in the header. I've also tried to deselect the shape and select the paragraph mark inside the header but I still get the same error message. I've even selected the paragraph mark in the header as well as the shape and still get the same error message.

    Very strange.

  4. #4

    Join Date
    Jan 2012
    Location
    Seattle, WA
    Posts
    4
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    In looking at this again, I'm noticing something that might be a clue. When the shape is created and thus "selected", the header window or pane (not sure what to call it) is not open but the shape is clearly selected. The same is true when I select the paragraph mark in the header - it's clearly selected but the header window/pane is not open - it looks as the though I'm in the main document but the selection is clearly not. By saying that the header/footer window or pane is not open, I mean that those "Header" and "Footer" upside down shaded tabs are not visible (if you double click on a document's header or footer the header/footer pane will open and these tabs appear).

  5. #5

    Join Date
    Jan 2012
    Location
    Seattle, WA
    Posts
    4
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Steve, your code works for me too. I'm thinking that because I SELECT the shape in order to set a few properties, this causes the macro to behave differently in some way. I still don't get why it still doesn't work when I deselect the shape and select the paragraph mark in the header.

SHARE:
+ Post New Thread

Similar Threads

  1. Local Administrator Password Puzzle
    By Andie in forum Windows
    Replies: 18
    Last Post: 11th February 2007, 09:14 PM
  2. Macro and VBA functions
    By randle in forum Windows
    Replies: 10
    Last Post: 9th February 2007, 09:32 AM
  3. Jigs@w Puzzle 2
    By sam67 in forum Downloads
    Replies: 0
    Last Post: 7th December 2006, 04:26 PM
  4. Spooky Puzzle
    By alan-d in forum Jokes/Interweb Things
    Replies: 19
    Last Post: 7th July 2006, 12:59 PM
  5. GP Folder Re-direction puzzle!!!
    By woody in forum Windows
    Replies: 15
    Last Post: 7th October 2005, 09:07 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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