Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry router security slow software sound toshiba trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Business Applications >
Modify BreakOnSection Macro To Save First Line As File Name

Reply  
Thread Tools
roadrunner12's Avatar
Junior Member with 1 posts.
 
Join Date: Mar 2009
31-Mar-2009, 09:01 PM #1
Modify BreakOnSection Macro To Save First Line As File Name
Hi All!

Just wondering if any of you could quickly help me with a problem I'm having.

I am using the BreakOnSection macro (see code below) which breaks up sections in my document and saves them as individual files. But instead of naming files "test_1", "test_2" "test_3" etc. I want to use the first line of each section for the file name.

Note: The first line will always have the same format, but the text will always change. Here is an example of one (without quotes):

"June 20 7pm - Coldplay, GM Place, Vancouver, BC"

Please see the code below to get a feel for what I'm working with, and if any of you could help, that would be greatly appreciated!

Code:
Sub BreakOnSection()
   ' Used to set criteria for moving through the document by section.
   Application.Browser.Target = wdBrowseSection

   'A mail merge document ends with a section break next page.
   'Subtracting one from the section count stop error message.
   For i = 1 To ((ActiveDocument.Sections.Count) - 1)
   
'Note: If a document does not end with a section break, 
'substitute the following line of code for the one above:
'For I = 1 To ActiveDocument.Sections.Count

      'Select and copy the section text to the clipboard.
      ActiveDocument.Bookmarks("\Section").Range.Copy

      'Create a new document to paste text from clipboard.
      Documents.Add
      Selection.Paste

   ' Removes the break that is copied at the end of the section, if any.
      Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
      Selection.Delete Unit:=wdCharacter, Count:=1
ChangeFileOpenDirectory "C:\"
      DocNum = DocNum + 1
     ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc"
     ActiveDocument.Close
      ' Move the selection to the next section in the document.
     Application.Browser.Next
   Next i
   ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub

Last edited by roadrunner12; 31-Mar-2009 at 09:06 PM.. Reason: Modified example
Reply

Tags
breakonsection, file name, first line, macro, word

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 12:07 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.