Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-08-2018, 07:06 PM
bobk544 bobk544 is offline Need to apply Heading1 to select rows Windows 7 32bit Need to apply Heading1 to select rows Office 2010 32bit
Novice
Need to apply Heading1 to select rows
 
Join Date: Apr 2009
Posts: 10
bobk544 is on a distinguished road
Default Need to apply Heading1 to select rows

Hello, i need to apply the Heading1 style to every every row that has the text string of
"C:\_XREF_ALL\App.2018" and the result i'm hoping for is that i will be able to collapse and expand the rows under each Heading1. And basically, this document contains a lot of program code and the beginning of each program starts with the C drive directory reference ie C:\_XREF_ALL\App.2018\Program1 for example. So i'm hoping that when i apply the Heading1 to the full row, i will be able to expand and collapse each program section of code, thanks for any help on this!



Code:
Sub HeaderApply()
Application.ScreenUpdating = False
Dim StrFnd As String, StrSty As String, StrRep As String, i As Long
StrFnd = "C:\_XREF_ALL\App.2018"
StrSty = " Strong,Heading 1,Character Style 1,Italic,Character Style 2"
StrRep = "Placeholder1^& Placeholder2,^&,^&,Placeholder3^& Placeholder4,^&"
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Forward = True
  .Format = True
  .Wrap = wdFindContinue
  .MatchWildcards = True
  .Text = ActiveDocument.Range  'trying to get the whole row text here
  .Replacement.Style = StrSty
  .Execute Replace:=wdReplaceAll
  'For i = 0 To UBound(Split(StrFnd, ","))
  '  .Text = "#" & Split(StrFnd, ",")(i) & "[A-Za-z]@>"
  '  .Replacement.Style = Split(StrSty, ",")(i)
  '  .Replacement.Text = Split(StrRep, ",")(i)
  '  .Execute Replace:=wdReplaceAll
  'Next
End With
Application.ScreenUpdating = True
End Sub

Last edited by macropod; 06-08-2018 at 07:28 PM. Reason: Added code tags
Reply With Quote
  #2  
Old 06-08-2018, 07:35 PM
macropod's Avatar
macropod macropod is offline Need to apply Heading1 to select rows Windows 7 64bit Need to apply Heading1 to select rows Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

For what you've described, all you need is:
Code:
Sub HeaderApply()
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
  .ClearFormatting
  .Forward = True
  .Format = False
  .Wrap = wdFindContinue
  .MatchWildcards = False
  .Text = "C:\_XREF_ALL\App.2018"
  With .Replacement
    .ClearFormatting
    .Text = "^&"
    .Style = wdStyleHeading1
  End With
  .Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
but you don't even need a macro for this - just an ordinary Find/Replace with 'Heading 1' specified as the replacement Style.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-08-2018, 07:56 PM
bobk544 bobk544 is offline Need to apply Heading1 to select rows Windows 7 32bit Need to apply Heading1 to select rows Office 2010 32bit
Novice
Need to apply Heading1 to select rows
 
Join Date: Apr 2009
Posts: 10
bobk544 is on a distinguished road
Default

Great thanks Paul i will try this first thing tomorrow and wow i see you're still around helping people out at all hours, amazing! You should unquestionably get some kind of special MS commendation of service award or something! And as a matter of fact, this app is still using a lot of the code you helped me on in the past and basically i'm using it to cross referencing hundreds of C++, C#, Java and Javascript programs and it helps a lot when analyzing complex code, so with this particular enhancement i'l be able to move blocks of code around easier in the order of the flow ect, thanks again Paul talk tomorrow!
Reply With Quote
  #4  
Old 06-09-2018, 05:24 AM
bobk544 bobk544 is offline Need to apply Heading1 to select rows Windows 7 32bit Need to apply Heading1 to select rows Office 2010 32bit
Novice
Need to apply Heading1 to select rows
 
Join Date: Apr 2009
Posts: 10
bobk544 is on a distinguished road
Default

Yeeha works great! many thanks again Paul! and now i can drag and drop whole sections of code over or under to create logical parent child hierarchies of code ect, super!

Ok so i'm going to tool around with this for a while and see if i can figure out a way to collapse and expand all sections with one command, so will get back to you soon, have a nice weekend Paul and great to see you're still out here wow!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to apply Heading1 to select rows Select rows w/cells containing given character strings, then sum cell in two other col. LarryHills Excel 1 02-17-2017 03:55 PM
VBA Word Table - Select More than 1 Column at a time - Apply Formatting jc491 Word VBA 12 09-24-2015 06:03 AM
Need to apply Heading1 to select rows TOC showing both Heading1 and Page Number FormatAdmin Word 3 03-04-2014 01:20 PM
Need to apply Heading1 to select rows reference previous heading1 fehenry Word 5 04-20-2012 01:54 AM
Heading1 does not convert to Kop1 boesh Word 8 07-02-2010 05:13 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:19 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