Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-13-2023, 10:54 AM
Jetheat Jetheat is offline Removing a Shape & Editing Header with Macro Mac OS X Removing a Shape & Editing Header with Macro Office 2016 for Mac
Novice
Removing a Shape & Editing Header with Macro
 
Join Date: Dec 2013
Posts: 21
Jetheat is on a distinguished road
Default Removing a Shape & Editing Header with Macro

Hi all,
I have a document which I receive on a daily basis and I have to edit the header each time.

Is there a way I can first remove the shape around all of my text pages (excluding page 1), because while that shape is there, I can't really edit the header. I am using Word on a Mac.

Once that is removed, is there a way I can take 4 different bits of information from Page 1, and paste that into specific places in the header?

Can all this be done with a Macro?

Appreciate the help,

JH

I have attached the document
Attached Files
File Type: docx Header-Change.docx (180.5 KB, 7 views)
Reply With Quote
  #2  
Old 11-14-2023, 02:39 AM
gmaxey gmaxey is offline Removing a Shape & Editing Header with Macro Windows 10 Removing a Shape & Editing Header with Macro Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
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

I don't have a mac so not sure if this will work or not:

Code:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim oSection As Section
Dim lngIndex As Long, lngShape As Long
  For Each oSection In ActiveDocument.Sections
    For lngIndex = 1 To 3
      For lngShape = oSection.Headers(lngIndex).Shapes.Count To 1 Step -1
        oSection.Headers(lngIndex).Shapes(lngIndex).Delete
      Next lngShape
    Next lngIndex
  Next oSection
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 11-14-2023, 03:32 AM
Jetheat Jetheat is offline Removing a Shape & Editing Header with Macro Mac OS X Removing a Shape & Editing Header with Macro Office 2016 for Mac
Novice
Removing a Shape & Editing Header with Macro
 
Join Date: Dec 2013
Posts: 21
Jetheat is on a distinguished road
Default

Thank you for this.

Yes, it does work, but it also removes the purpose-built line within the footer itself. I just wanted to remove the rectangle shape around the whole page.

Also, it removes the border from around Page 1, which I wanted to keep.

Can this be modified to take care of these two things?

JH
Reply With Quote
  #4  
Old 11-14-2023, 06:35 AM
Italophile Italophile is offline Removing a Shape & Editing Header with Macro Windows 11 Removing a Shape & Editing Header with Macro Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Why are you attempting to treat the symptoms instead of the cause?

Fixing the template that these documents are created from would solve the problem permanently.
Reply With Quote
  #5  
Old 11-14-2023, 09:29 AM
Jetheat Jetheat is offline Removing a Shape & Editing Header with Macro Mac OS X Removing a Shape & Editing Header with Macro Office 2016 for Mac
Novice
Removing a Shape & Editing Header with Macro
 
Join Date: Dec 2013
Posts: 21
Jetheat is on a distinguished road
Default

Quote:
Originally Posted by Italophile View Post
Why are you attempting to treat the symptoms instead of the cause?

Fixing the template that these documents are created from would solve the problem permanently.
This doc is given to me daily from work. I can't convince them to change the source!

JH
Reply With Quote
  #6  
Old 11-14-2023, 01:55 PM
gmaxey gmaxey is offline Removing a Shape & Editing Header with Macro Windows 10 Removing a Shape & Editing Header with Macro Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
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

Code:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim oSection As Section
Dim oRng As Range
Dim lngIndex As Long, lngShape As Long
 For Each oSection In ActiveDocument.Sections
   For lngIndex = 1 To 3
     For lngShape = oSection.Headers(lngIndex).Range.ShapeRange.Count To 1 Step -1
       oSection.Headers(lngIndex).Range.ShapeRange(lngShape).Delete
     Next
    Next
  Next
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 11-14-2023, 02:35 PM
Jetheat Jetheat is offline Removing a Shape & Editing Header with Macro Mac OS X Removing a Shape & Editing Header with Macro Office 2016 for Mac
Novice
Removing a Shape & Editing Header with Macro
 
Join Date: Dec 2013
Posts: 21
Jetheat is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
Code:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim oSection As Section
Dim oRng As Range
Dim lngIndex As Long, lngShape As Long
 For Each oSection In ActiveDocument.Sections
   For lngIndex = 1 To 3
     For lngShape = oSection.Headers(lngIndex).Range.ShapeRange.Count To 1 Step -1
       oSection.Headers(lngIndex).Range.ShapeRange(lngShape).Delete
     Next
    Next
  Next
lbl_Exit:
  Exit Sub
End Sub
Thanks a lot for the effort.

It now works by leaving the line in the footer, but it still removes the shape from around Page 1.

In fact, my real document has additional pages (attached), so is there a way to remove the shape from certain types of pages and to leave it on others?

Have a look at the attached doc.

JH
Attached Files
File Type: docx Header Change 2.docx (351.0 KB, 3 views)
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing a Shape & Editing Header with Macro Add Shape on every Header of each Section Souriane Word VBA 5 12-08-2022 06:35 AM
Adding text to the header and footer without removing all other content in the header and footer digitalelise Word VBA 2 10-23-2019 02:58 AM
Removing header from one page but not footer smithurmann Word 1 12-15-2018 11:24 AM
Removing header and footer on two pages in my document oliboi Word 1 11-01-2016 05:27 PM
selecting shape in header only mhagi Word VBA 5 10-09-2015 01:10 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:38 AM.


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