Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 31st, 2011, 09:22 AM
Registered User
 
Join Date: Aug 2004
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to webmeister
Default Replacing a range of text and keep formatting

I have a document that I am trying to print multiple times and print out a serial number on each copy via a Macro

in the document I have the SerialNum1 in the location where the serial number should be and formatted as it should look

It was suggested that I use to replace SerialNum1 with the current counter in the variable sn.

Code:
.Range.FormattedText = Replace(.Range.FormattedText, "SerialNum1", Format(sn, "000"))
When I run the macro, I am getting a Compile Error: type mismatch that highlights the Replace() part of .Range.FormattedText = Replace(.Range.FormattedText, "SerialNum1", Format(sn, "000"))

However, if I use
Code:
.Range.Text = Replace(.Range.Text, "SerialNum1", Format(sn, "000"))
it works however my entire document looses all of its formating and graphics.

Is there a way to make this work without the loss of my formating?
Reply With Quote
  #2 (permalink)  
Old February 5th, 2011, 03:01 AM
Friend of Wrox
Points: 2,950, Level: 22
Points: 2,950, Level: 22 Points: 2,950, Level: 22 Points: 2,950, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 788
Thanks: 1
Thanked 51 Times in 47 Posts
Default

Hi

You need to type over that. Try using Characters collection of the range and place the text

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing Text in NTEXT field tcarnahan SQL Server 2000 0 January 22nd, 2010 04:51 PM
Replacing text in text box inside table Larry Landis Word VBA 0 December 27th, 2007 11:03 AM
Replacing abbreviation with proper text Brendan Bartley Access 2 June 2nd, 2006 08:03 AM
Replacing Text with a String in a Form newgeek Beginning VB 6 2 August 14th, 2003 12:37 PM



All times are GMT -4. The time now is 12:30 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.