macro to copy text in word Results


Page 1 of 6.
Results 1...20 of 103

Sponsored Links:



Hi

I have this macro which supposed to copy the specific cell's value to certain location in Word, but it doesn't seem
to be working as expected. The "xlvalue2" and "xlvalue3" doesn't seem to be paste into the Word at all.
There is no error message. I am not sure what goes wrong here. Pls assist what need to be change in the
following codes.

Sub exceltoword()

Dim objWord As New Word.Application
Dim doc As Word.Document
Dim bmk As Word.Bookmark
Set doc = objWord.Documents.Open("C:My DocumentsMyfile.doc")
doc.Bookmarks("xlvalue1").Range.Text = Range("A1").Value
doc.Bookmarks("xlvalue2").Range.Text = Range("N3").Value
doc.Bookmarks("xlvalue3").Range.Text = Range("A7").Value
objWord.Visible = True

End Sub

TIA.

regards, francis




I have several workbooks that I need to copy data from row 9 onwards excluding text containing the word "total" in Col A and values to the right of the word total in the the destination workbook from row9 onwards. All the worksheets must be copied to the relevant worksheet in the destination workbook. The row containing the word total and the text bwelow that must be left intact

I have attached a sample source workbook "tax -br1" as well as the destination workbook "consolidated Tax.2012

Your assistance in this regard is most appreciated

See Link of cross post

http://www.excelfox.com/forum/f2/mac...-636/#post2716




Hello,

I recorded a macro to insert a printed watermark just by using Format, Background, Printed Watermark, choosing the Text Watermark option and entering the word COPY, changing the font size to 144 and removing the semitransparent selection. The VBCode returned having recorded the macro can be found in the attached .txt file.

However, when I run the macro on a document it debugs at:

Selection.ShapeRange.Name = "PowerPlusWaterMarkObject1"

I wonder if anyone can shed any light for me?

Also, I re-recorded the macro using the Format, Background, Printed Watermark, Picture Watermark feature inserting a .jpg I created which worked fine, however, if I then decide to remove the watermark by going to Format, Background, Printed Watermark the settings actually state there is No Watermark. Help??!!

Many thanks,

Violet ; )




I'm having problems with an old macro that has been updated and/or transferred every time I've updated Office. I'm sending a copy of it with this note. I use it most often when creating labels in a table. When I select the first column with text in the first cell, it works just fine -- copies info in first cell to remaining cells in the column. However, when I select the second column and run the macro, the macro selects the text in the first cell of column one and the first cell of column two, then qives me an error message to debug. It does the same thing in column three, selecting the text in the first cell of columns one, two and three. Could someone please check the attached macro and try to determine why it only works properly in the first column? I've highlighted the area that it says needs to be "debugged". Thanks.




Many of the documents in my office become corrupt and need to be repaired (The documents have come through many word processing applications and have all kinds of issues). The easiest way to fix these documents is to strip all the text out of the documents and paste the text into a new document. I've gotten the macro to do that much.

Here's where my problem begins: I can't make the macro save that new document back to the same path and filename. I would prefer that the new document replace the old document for 2 reasons. I don't want anyone to be able to open the old, corrupt document and copy it elsewhere (causing more problems), and I don't want the users to get confused by 2 documents on our system with very similar names.

I've tried inserting the document name and path in the original document then pasting it into the Save As dialog box of the new document, but the name and path isn't a static field. It changes with the document, so I can't use that method. Any suggestions?




We have text boxes placed in the first page and primary headers of some document templates so that we can add "stamps" to the document if the user wishes. These "stamps" would be text such as DRAFT, COPY, etc. The user can change and remove them with a macro which relies on a bookmark in each of the text boxes.

Occasionally the bookmarks get removed. I'd like to be able to replace the bookmark to the text boxes, but I'm having a bit of trouble writing the code. I always know the index of the text box, which I am supposing to be the Shapes collection. Is that correct. Can anyone offer a suggestion on how to set a range in Shapes(x) so that I can add a bookmark?

Thanks,
Richard Barrett




Forgive the detour in getting to my question but some background.

In FrameMaker, it's easy to create cross-reference styles--for example, one style can be used to create "See Section 123, Widgets, on page 20" and another style can be used to create "See Widgets ." Note that the first Xref is optimized for traditional print usage; the second is a standard hyperlink format (underlined, no page or section numbers). The actual Xref is constructed as a series of formats (italics, underlines), program functions (section and page numbers, title text), and constants ("See Section" and "on page "). These components are all strung together to make a named Xref template that can then be called to create the actual Xref. This is done in a manner akin to Word--pick an Xref target, click the Xref template you want, and Frame does the rest. This is very efficient from an authoring/layout perspective and it allows for some neat single-source alternatives.

I could, for example, have two document style sheets. The first is for print, the second for online. If I employ the same style names (including Xref template names) during tagging, I can, with a click or two, flip style sheets and go from a print doc with qualified Xrefs to an online doc with hyperlinks. Dump it out to Acrobat and I have the best of all worlds.

This is precisely what I need to do, in fact, with a book I'm working on. I'm constrained to using Word and the customer won't buy in to purchasing a copy of Quadralay, which would allow for reasonable HTML conversion (versus Word's truly ugly convert to HTML).

So, at long last, is there a way to achieve this in Word? Undoubtedly, it will require some degree of macro coding (about which I know less than my cat), but is this a feasible coding exercise? Or will I end up spending more time on the macros than on writing the book?

Thanks for any help, insights, or pointers to commercially available solutions for this requirement.

Charles




I set up a multilevel list style in Word 2007 for a client, following his specifications for the numbering/lettering and indents for each of the levels of the list. So far, so good.

When the client copies text that incorporates the style into an e-mail message (presumably in Outlook -- I believe the firm is using Outlook 2003), the list levels do not carry over. Instead, the list becomes a single-level list.

I have basic fluency in Outlook but don't use it regularly; my familiarity with the more advanced features is spotty. I'm wondering if there is any way to ensure that the multilevel list will paste intact from Word into Outlook.

Not sure if this is an Outlook question that should be moved or if it belongs in the Word forum, since I don't know where the problem lies or how to fix it (if it can be fixed).

The client says he was able to paste multilevel lists from Word 2003 into Outlook, which certainly makes it sound as if it can be done. (Unsurprisingly, he was not able to get a multilevel list to paste properly from WordPerfect into Outlook.)

Hoping for a simple solution, preferably one that doesn't require a macro.

Thanks in advance.

Jan




We have a protected Word form.

We need to send the form as an attachment, to an email address which is in the document text, automatically.

I created a macro to copy the email address that is in the document, and then run the File- Send To - as attachment command. There are a couple of problems with the macro:
1) When the email is opened, the user needs to click paste, to put the email address on the TO line. This isn't acceptable for the number of users of the form.
2) I have the macro execute when the last input field is exited. The last field is a comments field and may or may not be entered and exited by the user.
3) If the email address is moved to a different location in the document, the copy of it won't be correct

Is there any way to automatically plug the TO line in the email from within the macro. I am familiar with VBA code, but haven't found anything through help yet.
Since the form is protected, you can't just run the macro. Is there another idea of how I can automatically initiate the macro? Any other better ideas for any of this?

Thanks! Patty




I have created a macro which copies text from one document, does a paste special RTF into a new document. It works fine for all users, except one.

With this user when the text is pasted, it all of a sudden has tabs in front of each line. I've looked at the normal.dot, the auto text and checked to see if had a style attached.

I can't think of anything else.

Any help would be greatly appreciated.




In August, 2002 I posted macros to copy tables from a Word document or Excel spreadsheet to the clipboard, ready to be pasted into a post in the Lounge. My post was lost when Claude had to delete a large number of posts earlier this year.

Here is a reconstruction of the original post, with the attachment.

I thought it might come in handy to be able to create a simple table in Word or Excel and copy it to a post. I wrote a couple macros to achieve this. You will find them in the attached text file.

Notes:

Word
To make the macro available in all Word documents, you must put in into a module in Normal.dot or in a global template.
You can copy the text of the Word macro from the attached text file and paste it into a module.
You must have a reference to the Microsoft Forms 2.0 Object Library. To check this, in any module select Tools/References




If I search manually (in Word97) for text, with All selected, the search goes through the text, then through the headers and footers, but if I use a VBA macro, it goes through the "Story" only, without opening the headers and footers. Does anybody know how to make my macro search the headers and footers as well?

(I love STYLEREF, but in Wd2K, text in Unicode Hebrew doesn't display properly if it comes out of a STYLEREF, so I want to be able to harden the STYLEREFs in a document, once the source has been set.)

Here's my code, that handles the fields in the main document nicely, but doesn't look in the headers or footers. Any ideas?

Sub ReplaceStyleRefs()
' Get the head word text,
' then for each STYLEREF that refers to it,
' replace the field code with the text in the clipboard
'
Dim Found As Boolean
Dim FldCode As String

' If this document is a template,
' do nothing
'
If ActiveDocument.Type = wdTypeTemplate Then
MsgBox _
Title:="Macro to replace STYLEREF fields", _
Prompt:="Sorry, the active document is a template, so I won't change" & _
vbCr & "the STYLEREF fields into the Head Word."
Exit Sub
End If

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Head Word")
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Found = Selection.Find.Execute

If Found = False Then
MsgBox "Sorry, no text in Head Word style found."
Exit Sub
End If

Selection.Copy
Selection.Start = Selection.End
ActiveWindow.View.ShowFieldCodes = True

' Go through the document, replacing StyleRef fields as appropriate.
'
ReplaceStyleRefInternal

ActiveWindow.View.ShowFieldCodes = False
End Sub
Sub ReplaceStyleRefInternal()

Do
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^d"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Found = Selection.Find.Execute

If Found = False Then
Exit Do
End If

FldCode = Selection.Fields(1).Code
If InStr(1, FldCode, "STYLEREF", 1) Then
If InStr(1, FldCode, "Head Word", 1) Then
Selection.PasteSpecial Link:=False, DataType:=wdPasteText, _
Placement:=wdInLine, DisplayAsIcon:=False
End If
End If
Loop While Found

End Sub




I have an elaborate macro that loops through a (former WordPerfect) document multiple times to find various double-bracketed strings and then performs various formatting actions when it finds them. The macro works perfectly in its original version, but I've started to rewrite some of the code to work as much as I can with the Range.Find object rather than the Selection.Find object. For the most part, this is working, but some of the rewritten searches cause Word to freeze, forcing me to use Task Manager to shut it down.

The freezes always seem to happen in the immediate wake of a Range.Find that came up empty. Where it's a simple Find loop that is causing the freeze and the document has instances of the target, the code runs fine until it performs the final .Execute that returns False. Where it's a ReplaceAll version of .Execute, the code runs fine unless there are no instances of the target in the document.

The freezes are erratic only in the sense that much of my rewritten Range.Find code is working fine (including when the search comes up empty). But the freezes are consistent in the sense that a particular Range.Find that freezes in a particular document will always freeze at that same point in that same document (including if I'm stepping through the code).

Has anyone else experienced this kind of bugginess with Range.Find in Word 2002?

(P.S. I've tried throwing in DoEvents and pauses using Timer, but these haven't had any effect.)

(P.P.S. I should add that these are not "converted" WordPerfect documents. I'm copying the WordPerfect documents' contents (stripped of all codes) to the clipboard and pasting them into Word as unformatted text -- so I don't think the WordPerfect origin has anything to do with the Range.Find problem.)




Hi to all the lounge denizens

I wonder if someone can help me with this...

My challenge is to create a template that will be used by a large number of people across a complex network over some 20 sites around Australia, using everything from Word 2000 through to 2003. The basic requirement is that documents based upon the template need to display basic user details (e.g. name, email address, phone number) in the header or footer. So far, no problem - I'd collect the information using Fillin fields (I think?) and simply display the information where it's needed.

The challenge is doing it in such a way that each user only has to do it once, thereafter each new document based on the template will fetch the details from some store. And of course, there would need to be a facility to change the details at any time.

So what are the options? My first thought was to use Word's user properties - but they don't offer sufficient flexibility. I figured that it might also be possible to collect the info and store it somehow as variables within the template - but it's possible that some users will be running the template from a server and some locally - not to mention the security issues associated with mixing data with code. So without knowing much about how to actually do something like this, it occurred to me that the ideal way to go about this would be to collect the information and store it locally (perhaps as a text file somewhere foolproof like "My Documents" and maybe even set its "hidden" attribute).

In the re-use phase, I imagine the macro would first search for the text file in the nominated location. If the file was present, the values would be copied from the various fields into the new document. If the file was not present (i.e. first time the template is used or the file has been deleted), it would simply run the collection macro.

I have searched for posts that might point me in the right directio, but didn't find anything on the storage & retrieval aspects.

If anyone has persisted to this point in my ramble, I'd be most grateful - as always - for any suggestions from Team Lounge that might help me put some or all of this solution together.

Thanks and regards

Neil




Hi

I have an Unbound Text Box that is populated with several fields, e.g., name, address, town, etc. This enables anyone to select the text and paste it into Word or WordPerfect to create a single label, which can then be printed out on our Dymo Label Printer. I'd like to save a user a step or two by making it that they only have to click the Text Box and this would cause an OnClick Event to fire that copies the contents of the Text Box to the Clipboard. A Macro in Word or WordPerfect can then simply paste whatever's on the Clipboard into a document then format the document as a Label and print it.

So, my question is this: Is it possible to get Access to Select All and Copy to the Clipboard whenever someone clicks the Text Box? I've looked up the VBA Help, and the only thing I could see that resemble this is 'acOLECopy', but adding this to the OnClick Event doesn't work. I don't think it's meant to work this way.

If it's not possible, then I suppose I can create a form or report and format it to be a label, which can then be accessed by a command button that joins the Form via an ID Field, but I thought that this would be easier and would allow the user to use it in letters as well as just for labels.

Thanks in advance for your help and advice.

Brian [img]/forums/images/smilies/smile.gif[/img]




I searched for some help on this but couldn't find anything similar. I hope this is the right forum for this question.
I have an Excel app that opens a Word document which then copies the contents of the last selected cell from Excel to the document, and has a macro to store the text back in the cell when it is done. I have two issues:
1) There appears to be a difference between the CRLF in Excel and Word. When I store text from Word into an Excel cell that contains paragraph marks created while in Word they appear as rectangular boxes in the Excel cell but do not cause a carriage return line feed the way the "Alt-Enter" combination does. When I edit a cell in Excel with these boxes and interject "Alt-Enter"s there they appear, by their action and presentation, to be different but I created a series of Code statements to examine the characters in the cell and they all return a character code of 13 (consistent with the code I would use in Word VBA code to cause a CRLF). When the text is copied to Word they act like regular paragraph marks. and get converted to the rectangles when stored back in the Excel cell. I have attached two files; the workbook and a template. If you save them to any folder (but they have to both be in the same folder) they will work as long as you have only this one workbook open (no other instances of Excel or other workbooks open). Open the workbook and review my other comments below. Then let the macro attached to the "Edit" button create a Word document from the template to experiment. There is no real need to open the template directly. Cell A4 shows a comment with 4 "Enter"s after it. Cell A6 shows 4 "Enter"s I created in the Word doc and then edited in Excel to add "Alt-Enter" after the second, third, and fourth one. You can see that they look different but A8-A13 show they all have a code of 13. My machine is so slow that I can see this cell change in the Excel formula bar to 5 rectangular boxes while the macro is running prior to the Word window coming up but I don't know what that means. Does anybody know what is happening here? I'd like to have the paragraph marks in Word turn into "Alt-enter"s in Excel so as much of the comment as possible appears the same in Excel as it does in Word.

2) I'd would love to hear from anyone who knows a better way to do this but so far this is the only way I have found to address some issues my users are complaining about. One issue is a cell being able to hold 32,767 characters but display only 1,024. Even that is sometimes cut off because the autofit row height doesn't expand enough to show the whole 1024 characters. Another is the spell checker but I found an article that would allow the use of the Word spell checker in Excel. The user has asked for a "Word or Word like window to edit the text" and I'm trying to accommodate. I'm even open to using another application.
Thanks for any help or ideas you can offer!




I'm trying to insert an existing Microsoft Word Document Object, then open the object (so I can adjust some of the text in the object), and then close it again. However, when I get to the step of closing the document, I get the following error:

I was getting the following error when I stepped through the macro at the step of closing the document object, but now I just get it if I run it from Tools>Macro>Macros:

WINWORD caused an invalid page fault in
module MSO9.DLL at 017f:308f8a93.

Now for some reason I am getting the following two IPF's when I try to step through it after reaching the end of the sub and hitting the ALT key or trying to view the document again (since steping through is done in the VBA editor):

WINWORD caused an invalid page fault in
module at 0000:00000007.

WINWORD caused an invalid page fault in
module WINWORD.EXE at 017f:30127d8e.

I looked at the knowledge base articles on Microsoft's sight, but none seemed to apply to my situation. I tried some of the fixes they recommended as well, but to know avail. I also check the references to mso9 on this forum, but could not find my situation.

As I have the macro so far, all I am doing is opening and then immediately closing the object.

'This is the code I am using to insert the object:
Selection.InlineShapes.AddOLEObject ClassType:="Word.Document.8", FileName _
:="E:My DocumentsGoalsObject.doc", LinkToFile:=False, DisplayAsIcon _
:=False

(I have tried changing "Word.Document.8" to "Word.Document.9", but it does not make a difference.)

'This is the code I am using to open the object after I select it:
Selection.InlineShapes(1).OLEFormat.DoVerb VerbIndex:=1

'This is the code I am using to close the object (and also where the error occurs):
ActiveDocument.Close

I tried to copy just this module to a separate document and run it, but I don't get the error message. I have tested and tested and beat my head against the wall a few times , and I still can't figure out why I cannot reproduce the problem outside this document.

I have not run any other procedure before running this macro, so I cannot figure out why it makes a difference to have only this procedure in a document. I am baffled.

Also, it would be nice if I could use a relative path, but when I put the object in the same directory as my main document containing the macro, it tells me "Word cannot obtain the data for the Object.doc.lnk".

The code when trying this looks like this:

Selection.InlineShapes.AddOLEObject ClassType:="Word.Document.8", FileName _
:="Object.doc", LinkToFile:=False, DisplayAsIcon _
:=False

Please help!!
Troy




I created the below macro in Word that allows me to make selected text both bold and italics with one click on an italicized "B" icon I created and added to my Word tool bar. It works great - I also assigned the shortcut Ctrl-Alt-b to the macro for the keyboard commando in me.

Sub BoldItalics()
'
' BoldItalics Macro
' Macro created 1/28/2000 by Bill
'
Selection.Font.Bold = wdToggle
Selection.Font.Italic = wdToggle

End Sub

Now I want to create the same thing in Outlook for when I create email and want text bold and italicized (I don't want to make Word my email editor) - so I copied the above macro and pasted it in Outlook's macro editor but received a run-time error '424' object required and then the de###### highlights the two action lines. Since Outlook does not have a macro recorder and I am not a coder, I am lost. Ideas?

Thanks




I have a complaint about a new "feature" of Microsoft Word XP that causes screen captures and other low to moderate resolution images pasted into Word to look fuzzy while editing the document. I frequently copy CAD-type drawings or scientific graphs from their parent applications to a notebook I keep in Word. I always first paste the "image" (actually object) into Paint Shop Pro to intentially discard the object information, then re-copy, and paste the raw image into Word. I use this method since the original objects are typically quite large, and I already keep the original file around, so I don't need to bloat my Word documents any more than usual with object info.

Ever since we upgraded from Word 2000 to Word XP, I have noticed that when I paste an image from Paint Shop Pro into Word it looked sort of fuzzy, especially screen capture images. Looking into this, I found that you can choose Paste Special from the Edit menu when pasting an image and you will see 3 choices: Paste as Picture, Paste as Bitmap, or Paste as Device Independent Bitmap. Microsoft claims the "Picture" mode is better for high quality printers and results in smaller file sizes while Bitmap is an "exact reproduction" of the original image and takes up more disk space.

Experimenting with the various Paste Special modes I found that the default action when pasting an image is to paste is as a "Picture". It appears that Microsoft is, in effect, turning the image into a JPEG-type image to fit the space available on the page. Converting pictures of people to JPEG images usually doesn't matter, since the picture still looks good. However, converting diagrams, plots, or screen captures to JPEG images is usually a bad idea, as straight lines become fuzzy, etc. The second downside of pasting an image as a "Picture" is that it ends up about 90% of the size of the original image -- again you lose some detail.

Thus, it looks like the best solution for me is to use Paste Special and choose BitMap. I believe this is the behavior that versions of Word prior to XP would do, and it is more appropriate for diagrams and plots. I would suggest to the Word designers that they create a Smart Tag to appear when pasting images to give the choice of how to paste it, similar to the Smart Tag that appears when you paste text from a web page, allowing you to easily convert to raw, unformatted text.

Interestingly, I pasted the same image into a document, first as a Picture, then secondly as a Bitmap, then printed out the document, and I could not see a difference. Still, when editing documents on the screen, the difference is quite apparent. The only downside is that when pasting an image as a BitMap it will take up slightly more disk space, especially if it is very large BitMap (several times the size of the screen). As a test, I pasted 5 copies of 630x475 pixel image into two documents, first as a "Picture" and secondly as a BitMap. The file sizes when saved to disk were 101 Kb for the "Picture" document and 123 Kb for the BitMap document. Thus, the BitMap document is 25% larger, which, in my opinion, is a small price to pay for better looking images.

Because I got tired of always choosing Edit | Paste Special -- Bitmap for each picture, I wrote a simple two line macro to paste the image as a Bitmap, then bound the macro to a custom icon on my toolbar:
'' Sub PasteAsBitmap()
'' On Error Resume Next
'' Selection.PasteSpecial Placement:=wdInLine, DataType:=wdPasteBitmap
'' End Sub
The On Error Resume Next was necessary in case the info on the clipboard is not a bitmap. The wdInLine was necessary to achieve the correct pasting behavior of inline rather than floating over text.

Finally, now that I've completed by diatribe, I do have one question. Once I've pasted an image into Word (say a Screen capture, cropped to a reasonable size), I sometimes then want to export the image back out of Word and edit, again, typically with Paint Shop Pro. If I select the image in Word, choose copy, then Paste into Paint Shop Pro, I find that it has pasted a JPEG-esque representation of the image, adding random pixels in the solidly colored areas and decreasing the number of colors. The only workaround I have found is to take a Screen Capture of the Word document!! then paste into Paint Shop Pro and crop. Better alternatives? One clue as to what might be going on is that if you choose Edit | Paste Special after copying the bitmap in the Word Document, there are now a number of new choices, including Picture (GIF), Picture (PNG), and Picture (JPEG). Pasting (into Word) as a PNG or GIF looks good (sometimes, though I was getting some large black or white blocks sometimes), while pasting as a JPEG looks just like the picture that appears in Paint Shop Pro.

Matt




I recorded a macro to paste unformatted from the clipboard and the macro reads:

Selection.PasteAndFormat (wdPasteDefault)

While recording, I specifically selected Paste Special, followed by Unformatted Text. When executed, the macro pastes but does not paste unformatted. It takes on the formatting of what it copied. Can someone give me a simple correction?

Thanks,
Bob in Seattle


Page 1 of 6.
Results 1...20 of 103