Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy records to word from excel 3

Status
Not open for further replies.

jkasu

Technical User
Aug 14, 2011
2
If I try to run following script in word it gives error but if I use same in excel its fine. I am running word template to open excel sheet and then search for record in first row

Columns("A:A").Select
Selection.Find(What:="OBS", After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False).Activate
 
You have to fully qualify your Excel objects:
yourXLappObj.Columns("A:A").Find(What:="OBS", After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False).Activate


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you PHV for the feedback. As am not a programmer I am still getting problem please advice as i am getting run time error type mismatch

Dim xlWB As Excel.Workbook
Dim xlApp As Object
Dim i As Integer
Dim ws As Worksheet
Dim text1 As String
text1 = InputBox(Prompt:="Job No.", _
Title:="Enter Job No", Default:="Last record")
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlWB = xlApp.Workbooks.Open("C:\test Job Register.xls")



With xlWB.ActiveSheet




If text1 = "Last record" Then GoTo lastrecord1
xlApp.Columns("A:A").Find(What:=text1, After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False).Activate
Columns("A:A").Select

GoTo cont1
lastrecord1:

Range("A65536").End(xlUp).Select
cont1:
userid.Value = ActiveCell.Value
engineer.Value = ActiveCell.Offset(0, 14)
con.Value = ActiveCell.Offset(0, 4)
dor.Value = ActiveCell.Offset(0, 1)
js.Value = ""
it.Value =
 
Welcome to Tek-Tips.

To improve the presentation of your code use TGML tags like this:
[[]Code]your code[[]/Code]

Code:
 xlApp.Columns("A:A").Find(.....
Does not explicitly say which workbook or worksheet in the workbook. I suggest
Code:
 [red]xlWB.Activesheet.[/red]Columns("A:A").Find(.....
or, because this statement is within a [red]With xlWB.ActiveSheet[/red] statement:
Code:
 .Columns("A:A").Find(.....

You didn't say what line of code is highlighted when you get the error.

Gavin
 
Jkasu,

Is there a reason you can't use a (filtered) mailmerge for this?

Cheers
Paul Edstein
[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top