Copy formatted text but not headers/footers

I have the following VBA code to copy some text from between Word documents 
(I'm familiar with VBA but not the Word object library):

Const PLACEHOLDER_TEXT As String = "||ADD TEXT HERE||"

' Copy from source to clipboard
docSource.Activate
docSource.Sections(x).Range.Copy

' Paste from clipboard to target
docTarget.Activate
Selection.Find.Execute PLACEHOLDER_TEXT, , , , , , True, 
WdFindWrap.wdFindContinue
Selection.Paste

What I want is for the section's formatted text to be copied/pasted into the 
existing section in the target document so that the headers/footers in the 
target document are preserved. 

However, what seems to be happening is that the copied text is pasted as a 
new Section object including the now empty headers/footers.

In other words, I want the formatting (fonts, tables, borders, etc) from the 
source document but not the headers/footers. Is this possible? Thanks
0
Utf
4/27/2010 3:15:01 PM
word.docmanagement 5542 articles. 2 followers. Follow

1 Replies
2241 Views

Similar Articles

[PageSpeed] 56

It seems the root of the problem is that selecting the Section.Range object 
included the page break. 

The fix I'm going with is to move the selection end of the back until the 
end character is anything other than ASCII 0012 or 0013 e.g. 

Replace this:

docSource.Sections(x).Range.Copy

....with this:

docSource.Sections(x).Range.Select
Do While (Asc(Right$(Selection.Range.Text, 1)) = 12 Or 
Asc(Right$(Selection.Range.Text, 1)) = 13)
  docSource.Range(Selection.Start, Selection.End - 1).Select
Loop      
Selection.Copy

No doubt there are betters way of doing this things than using the clipboard 
and the Selection object but this will do for now :)

"Jamie Collins" wrote:

> I have the following VBA code to copy some text from between Word documents 
> (I'm familiar with VBA but not the Word object library):
> 
> Const PLACEHOLDER_TEXT As String = "||ADD TEXT HERE||"
> 
> ' Copy from source to clipboard
> docSource.Activate
> docSource.Sections(x).Range.Copy
> 
> ' Paste from clipboard to target
> docTarget.Activate
> Selection.Find.Execute PLACEHOLDER_TEXT, , , , , , True, 
> WdFindWrap.wdFindContinue
> Selection.Paste
> 
> What I want is for the section's formatted text to be copied/pasted into the 
> existing section in the target document so that the headers/footers in the 
> target document are preserved. 
> 
> However, what seems to be happening is that the copied text is pasted as a 
> new Section object including the now empty headers/footers.
> 
> In other words, I want the formatting (fonts, tables, borders, etc) from the 
> source document but not the headers/footers. Is this possible? Thanks
0
Utf
4/28/2010 8:31:02 AM
Reply:

Similar Artilces:

format based on data from another cell
I want the names in column B of my spread sheet to highlight either red or yellow based on the value of the cell in column L, but with conditional formatting you can only format based on the value of the cell you are formatting, as far as i can tell. Hi Sanna conditional formatting can be used to do this, select the column B cells that you want the formatting to be applied to, ensure that the first selected cell is the first line visible at the top of the worksheet choose format / conditional formatting choose formula is type =$L2=x where row 2 is the first row in the selected column an...

Using VLOOKUP and text
I am using a Vlookup function to find dollar values, dates, and names of vendors made within a department. The dollar values are appearing correctly, but the dates appears as "01/00/00" when the field is empty and all the text strings appear as "0" even though there is a name in the source sheet. I have changed the formatting of each cell to be correct to the appropriate format (accountancy, date, text) and even tried 'general' to fix this text problem to no avail. HELP!! If A1 is empty, and you put this in B1: =a1 You'll see it returns a 0. Same thing...

number formatted cell
If I am typing in 19 numbers in a cell (that has been formatted to number) to keep track of account numbers, it puts zeroes at the end and only 15 numbers are showing. If I go into another cell and choose text first before typing and then type my numbers you can see all the numbers, but when I try to go and change the number formatted cell to text the number still does not change unless I retype the number. Is this the way this works? yes excel only keeps track of the first 15 digits in a number, if you entered more digits as a number,they are now lost. "Pam Coleman" wrote...

using GETPIVOTDATA feature and need to keep formatting
I want to copy a value from a pivot table and am combining it with text using the =(C1&" "&(Getpivotdata....)) feature. The values in the pivot table are monitary and I'd like to keep the $ sign and '000 comma but the formatting disappears (ie no comma or $ sign) Thanks =(C1&" "&TEXT((Getpivotdata....),"$#,##0.00")) -- Hope this helps. If it does, please click the Yes button. Thanks in advance for your feedback. Gary Brown "CTTTTT" wrote: > I want to copy a value from a pivot table and am combin...

Formatting drop-down menus
How do you change the size of font used to display options in a drop-down menu placed on a spreadsheet? I have tried formatting the default font size for the spreadsheet & the font size in the cell range used for the drop-down menu options but neither worked and I can't find anything in the help files. Windows XP home, Office 2000 Premium, All updates installed. You can't change the font size for a Data Validation dropdown list. However, you can use programming to adjust the zoom setting when the cell is selected. There's some sample code here: http://www.context...

Copying Formatting Styles
I am using Word 2003. When I copy text from one document to another all the underlying formating, including bullets, headers etc do not get copied. This does not happen always though. I tried copying formatting styles from source document to destination using Windows Organizer but that did not help. Please advise. Thanks. By default, the destination styles will be used when you copy text from one Word document to another. In your case, you may want to reverse the process: Instead of copying text from document A to B, copy the relevant pieces of text from document B to documen...

Selecting Font Colors
Greetings group, my 1st post here. I've been trying to figure out how to use/create additional text font colors beyond the 40 palate or 16 additional in the Format Cells dialog. Is this possible? Is there a show codes area to tweak? or better still a color wheel for the Text Font Color available. I'm using: Microsoft(R) Office Excel 2003 (11.8012.6568) SP2 - thanks in advance M.D. About all you can do is modify the existing colors under Tools>Options>Colors>Modify. This is not a global change, just a workbook by workbook basis. You can import your modified scheme...

excel not updating text boxes
i have several charts with textboxes lind to specific cells within my workbook. inside these cells are formulas that calculate values that I am trying to display on my charts in the text boxes. My calculations are set to automatic, but these text boxes are not updating unless i click in the formula bar for each of them and hit "enter." since i have several charts i don't want to be doing this hundreds of times a day. I have a total lack of confidence that my chart text boxes are displaying the correct values. is there some way to force them to update, maybe wit...

Conditional Format Tracker by Date
I'm building a tracker to make sure paperwork is done on time. Headers: A:Name B:IDNum C:Phone D:StartDate E:Plan F:Paperwork G:30DAuth H:90DAuth I'd like to use conditional formatting to compare the dates and color the cells for easier tracking. The compare TO date is column D. In column E, we have 7 days to write the plan so if there is no date in that column, turn red. When a date is entered turn green if within 7 days but yellow if it's past 7 days. In column F, same as column E but only 3 days for that one. (I can figure that out if I get a w...

Copy an email to a saved folder
I get some emails and want to save them immediatly to the "saved" while still having a copy in the " inbox" to respond to but there is no "copy to folder" button in the drop down list, such as there is in Outlook express. Can I get one in there somehow. If I save it to a word file I then cannot respond to it. On Tue, 17 May 2005 11:57:18 -0700, miltdp <miltdp@discussions.microsoft.com> wrote: >I get some emails and want to save them immediatly to the "saved" while still >having a copy in the " inbox" to respond to but there is...

How do I read text file in an EXCEL SHEET
Hello, With regards to EXCEL how we read the text file in EXCEL sheet using MACRO. The file is located in d:\Sql\Documents\Amit\log.txt. I want to save the EXCEL sheet, and every time when I open this sheet it reads this text file and displays the contents of this text file in Excel Sheet. I want to use MACRO for reading this text file.How I do that? Thanks Amit fileName = "D:\Sql\Documents\Amit\log.txt" Workbooks.OpenText FileName:=fileName OR Workbooks.OpenText FileName:=fileName, Origin:=xlWindows, StartRow _ :=1, DataType:=xlFixedWidth, FieldInfo:=Array( _ Array(0,...

Conditional Formatting #3
Hi all I have this conditional format in cell BB35 =IF(BB35>$BB$37,TRUE) If I insert cells between BB35 & BB37, then the formula changes to =IF(BB35>$BB$38,TRUE) Is there a way of making BB37 absolute, or is there a formula using ROW that I could use? Many thanks -- George Gee -- Select cell B35 Choose Format>Conditional Formatting From the first dropdown, choose Formula Is In the formula box, type: =B35>INDIRECT("$B$37") Click the Format button and select your formatting Click OK, click OK George Gee wrote: > I have this conditional format in cell BB35...

5pt space between paragraphs when copied from Word to Publisher
When I copy several paragraphs from a word document and paste it in Publisher I always get 5pts added before and after each paragraph. Is there anyway to change this so I don't have to delete the space each time? I have Office version 2003 and Windows XP. Paste special as unformatted text... or Select all, Format, Paragraph, change the before and after. -- Mary Sauer http://msauer.mvps.org/ "BoKay" <BoKay@discussions.microsoft.com> wrote in message news:0EB4C534-F64D-409D-AC89-37367675C71D@microsoft.com... > When I copy several paragraphs from a wo...

How to copy a Macro to another PC
How can I find and copy an Excel macro to another PC. As I recall the one I created also created a file called Personal.xls that automatically opens up. Not sure if this is the only file that needs to be copied? Also, where does it get copied to? What location? Same as original PC? -- FL Personal.xls is automatically opened (if it exists) but is hidden; use Widows | Unhide to see if you have one. Generally it is kept in the XLSTART folder; find it with a search. However, some people have Excel open other files automatically; Use Tools | Options and look on the General tab to see ...

Can I Apply Conditional Formatting to a Chart?
I don't agree with my boss's ideas regarding Excel Charts - I think that they are to cluttered and become less effective. So, I would like to apply conditional formatting via a checkbox to "turn off"(apply white/transparent properties)to one or more series in a chart, effectively eliminating the overlapping series from view temporarily. Can this be done? Is the answer VB?I think this could be very effective in clarifying data that is consistently overlapping each other. (Actually I would just make 3 separate charts on the same page, but nobody is asking me!) Tell me w...

Auto format causes very large .xls files and slows my application.
I don't know how many rows of data will be entered at runtime. Presently I guess the maximum and apply auto format conditions to all rows that "could" be used. But this is creating very large .xls files (35MB) and is very inefficient since every cell format is reassessed every time the workbook is modified (can't switch off auto calc since users will forget to calc ! it's ok for me but not them.). Without using VBA, is there a way to apply auto format to rows containing data ? Select the range, then use Format - Autoformat. -- Earl Kiosterud mvpearl omitthis...

Change Text Case
Anyone know how to change the case (from all caps to lower case, or just first letter cap) without retyping all the text in a worksheet? Thanks! a formula =lower(a1) =proper(a1) -- Don Guillett SalesAid Software donaldb@281.com "Chel" <anonymous@discussions.microsoft.com> wrote in message news:09A9342E-9DED-4BB7-8C08-1DA31E7CEBCB@microsoft.com... > Anyone know how to change the case (from all caps to lower case, or just first letter cap) without retyping all the text in a worksheet? Thanks! Chel, You can use a macro like the following: Sub ConvertCase() Dim Rng As ...

Text Wrapping not working as desired.
I have a workbook containing several worksheets. The specific worksheet of concern is set up to allow the user to fill in information and as such will be protected to eliminate the risk of changes. All cells have been set as Protected except those where the user is allowed to fill in data, AND those cells have had Wrapping enabled (actually, the whole row (NOT the whole worksheet) has had wrapping enabled). However the row is NOT auto expanding when the data is entered, rather the row remains the height of a single row and never displays more than the first line of text. This is an iss...

Cannot copy table from Excel 2007 to Word 2007 w invisible grid li
How do I copy a table from Excel 2007 to Word 2007 with invisible grid lines? In previous version of Word, it was possible to do so by clicking on "insert special" and choose one of the categories (I have forgotten which). With Word 2007, the grid lines become visible no matter which option I choose under "insert special". Is it possible for you to help me? Thanks! To hide the gridlines, click the View Gridlines button (to deselect the option) on the Table Tools Layout tab. This setting will be preserved between Word sessions. If you are in fact referr...

suppressing a footer only on the first page of a printout
Is there a way to suppress a footer on the first page of a printout, but let it print on all subsequent pages? Thanks in advance, Paul Is there a way to suppress a footer on the first page of a printout, but let it print on all subsequent pages? Thanks in advance, Paul Take a look here: Print different first page headers or footers http://www.mcgimpsey.com/excel/subs/firstfooter.html In article <eukpiSzAFHA.936@TK2MSFTNGP12.phx.gbl>, "Paul James" <pponzelliBEGONE@dfiSPAM.caFOREVER.gov> wrote: > Is there a way to suppress a footer on the firs...

locking a text box in a subform
Hi there, I've got a form that looks like this: MAIN FORM SUBFORM1 SUBFORM2 SUBFORM3 I'm trying to code an event in a listbox in SUBFORM1 that locks a textbox in SUBFORM2 if the user picks a certain item from the list. However, I can't seem to get the code right in order to do it. I tried this: If whatever Then Forms!subfrm1.subfrm2!Listboxname.Locked = True End if However it keeps telling me it can't find subfrm1. Any ideas? jjmclell On Aug 22, 8:55 am, jjmcl...@lakeheadu.ca wrote: > Hi there, > > I've got a form that looks like this:...

2 copies of every new e-mail!
I asked my computer guru to make sure my e-mail goes to my desktop PC and my laptop. That seems to be working, but now I am getting 2 copies of every e-mail in my inbox Can somone tell me how to turn this off so I only receive one copy of each e-mail? On 30 Apr 2004 10:06, "Mark" <anonymous@discussions.microsoft.com> wrote: >I asked my computer guru to make sure my e-mail goes to my desktop PC >and my laptop. That seems to be working, but now I am getting 2 copies >of every e-mail in my inbox. > >Can somone tell me how to turn this off so I only receive one...

Downloading page format from net
Hi friends My first ever post.... I have a web page whose template is fixed. Every half hour the page gets updated. There are 10 rows (say 10 Students in a class) and 9 cols ( say there subjects). Every half hour this web page gets updated and i want that data in one excel page. after getting the updated data, it should be transferred to other sheet (will be 10 say for each student) These respective sheets will have another column with date and time data which will be taken from the web page...... A friend of mine told me this could be done in Excel but dont now how to do it...!!!!!:eek:...

Text Color Format Does not stick
I have text in a cell and I applied the color red but as soon as I go to the next cell, it changes back to orignal text formatting. What could be the cause? DISREGARD this posting. "Roberta" wrote: > I have text in a cell and I applied the color red but as soon as I go to the > next cell, it changes back to orignal text formatting. What could be the > cause? ...

Add Header Automatically to the Chart
How can I take the information written in the cell A1-sheet1 and then put it automatically in the header of the chart that already created. Thanks in advance. Maperalia Use Chart Options to add a chart title such as Junk On chart, select the dummy title and in the formula bar type =, now click on cell A1; press Enter Done best wishes -- Bernard V Liengme www.stfx.ca/people/bliengme remove caps from email "maperalia" <maperalia@discussions.microsoft.com> wrote in message news:6D260E0B-3334-47C2-A57B-23E7435161F8@microsoft.com... > How can I take the information written...