Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Excel to Word

Hey,


I'm trying to make a macro that reads a column in Excel.I've only ever
done VBA for excel and this is confusing me. I need the macro to read
the cell in excel and find it in the word document, then copy the 20
charactors to the right of the found numbers and paste them in excel.
And loop this for a complete column


I know thats a little confusing but if you need any clarification or if



you could help please let me know.


Andrew

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Excel to Word

Andrew:

Below is some sample code to accomplish something similar to what you
described. Obviously, you will have to adjust it to your specific needs.
You will need a reference to the Word Object Library, of course.

Public Sub FindWordString()
Dim i As Integer
Dim sFind As String
Dim wd As New Word.Application
Dim doc As Word.Document

On Error GoTo Errorhandler

'Open the word document
Set doc = wd.Documents.Open("H:\TestDoc.doc")

'Macro assumes ActiveCell is at top of column of search values
For i = 1 To ActiveSheet.UsedRange.CurrentRegion.Rows.Count
'Grab the search value
sFind = ActiveCell.Value
'Select the entire Word document
doc.Select
'Perform the find
doc.Application.Selection.Find.ClearFormatting
doc.Application.Selection.Find.Text = sFind
doc.Application.Selection.Find.Execute Forward:=True
'Our search value is now selected, so move one character to put
cursor at end of search value
doc.Application.Selection.MoveRight Unit:=wdCharacter, Count:=1
'Select the next 20 characters
doc.Application.Selection.MoveRight Unit:=wdCharacter, Count:=20,
Extend:=wdExtend
'Copy
doc.Application.Selection.Copy
'Paste in column to the right of search value
ActiveCell.Offset(0, 1).PasteSpecial xlPasteValues
'ActiveCell is now in paste column so adjust and select next search
value
ActiveCell.Offset(1, -1).Select
Next i

FindWordString_Exit:
doc.Close
wd.Quit
Set doc = Nothing
Set wd = Nothing

Exit Sub

Errorhandler:
If Err.Number < 0 Then
MsgBox "Message: " & Err.Message, vbCritical, "Error"
Resume FindWordString_Exit:
End If

End Sub


--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


wrote in message
oups.com...
Hey,


I'm trying to make a macro that reads a column in Excel.I've only ever
done VBA for excel and this is confusing me. I need the macro to read
the cell in excel and find it in the word document, then copy the 20
charactors to the right of the found numbers and paste them in excel.
And loop this for a complete column


I know thats a little confusing but if you need any clarification or if



you could help please let me know.


Andrew


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Excel to Word

Wow,

Thanks alot

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Excel count of 1 word if found in multi-word cells of column Function_Challenged Excel Worksheet Functions 1 August 27th 09 12:08 AM
Excel 7, paste linked to word becomes black when word pdf'd Surffreak Excel Discussion (Misc queries) 0 June 1st 08 12:17 AM
Copy from Word to Excel, and retain indent, plus word wrap Eric Excel Discussion (Misc queries) 1 March 9th 07 03:15 AM
Print labels by using Excel data in a Word mail into word Zoey Excel Discussion (Misc queries) 1 November 1st 05 09:08 PM
Printing Word Document using Excel Programming hangs Word Alan Excel Programming 0 September 30th 04 08:41 PM


All times are GMT +1. The time now is 04:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"