PDA

View Full Version : What is the error?



clif
02-09-2012, 08:26 AM
This is the excel vba. What is the error.:banghead: Thank you very much!


Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Open("C:\abc.doc")



Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
wrdApp.Selection.GoTo What:=wdGoToBookmark, Name:="a"
wrdApp.Selection.PasteExcelTable False, False, False


'error
Dim wkb As Excel.Workbook

Set wkb = Thisworkbook
'error

wrdApp.Selection.GoTo What:=wdGoToBookmark, Name:="b"
wrdApp.Selection.MoveRight Unit:=wdCharacter, Count:=10
wrdApp.Selection.TypeBackspace
wrdApp.Selection.TypeBackspace
wrdApp.Selection.TypeBackspace
wrdApp.Selection.TypeBackspace
wrdApp.Selection.TypeBackspace
wrdApp.Selection.TypeBackspace
wrdApp.Selection.TypeBackspace
wrdApp.Selection.TypeBackspace
wrdApp.Selection.TypeBackspace
wrdApp.Selection.TypeBackspace


'error
wrdApp.Selection.TypeText wkb.Worksheets("1").Cells(1, 1)
'error


Set wkb = Nothing




wrdDoc.SaveAs "D:\abc.doc"


wrdDoc.Close
wrdApp.Quit
Set wrdDoc = Nothing
Set wrdApp = Nothing

Bob Phillips
02-09-2012, 08:28 AM
Wrong forum.

clif
02-09-2012, 05:18 PM
I do not know how to define the workbook. It is excel vba to control word file. Anyone can help!

Kenneth Hobs
02-09-2012, 09:34 PM
Review these to see what you need.

'TypeText method
' http://www.excelforum.com/excel-programming/650672-populate-word-document-from-excel.html#post1946784
' http://www.excelforum.com/showthread.php?p=1946784
' http://vbaexpress.com/forum/showthread.php?p=169877
' http://vbaexpress.com/forum/showthread.php?t=24693

'Copy from Excel, paste to Word
'Lucas, http://vbaexpress.com/forum/showthread.php?p=178364

'FormFields
' http://www.mrexcel.com/forum/showthread.php?p=1639696
' http://www.mrexcel.com/forum/showthread.php?t=333200

'Add Hyperlink to Bookmark
' http://www.excelforum.com/excel-programming/664078-use-excel-vba-to-add-a-hyperlink-to-a-word-document.html#post2006430
'Steiner, http://www.vbaexpress.com/kb/getarticle.php?kb_id=126
'Colin_L, http://www.mrexcel.com/forum/showthread.php?t=358054

'Save OLEObject as MSWord Document
' http://vbaexpress.com/forum/showthread.php?t=21619

'Add Table to MSWord
' http://vbaexpress.com/forum/showthread.php?t=23975
' http://vbaexpress.com/forum/showthread.php?p=168731

'Import Word Tables
' vog, http://www.mrexcel.com/forum/showthread.php?t=382541

'Save OLEObject as MSWord DOC
' http://www.mrexcel.com/forum/showthread.php?p=2809902
' http://vbaexpress.com/forum/showthread.php?t=21619

'Get Optionbutton info from MSWord DOC
' http://vbaexpress.com/forum/showthread.php?t=22454

'FindReplace Text
' http://www.excelforum.com/excel-programming/682014-replace-word-in-ms-word-with-varable-from-ms-excel.html
' Multiple Find/Replace
' http://www.excelforum.com/excel-programming/794297-struggling-with-a-find-replace-macro-to-word.html
' Single Find/Replace
' http://www.vbaexpress.com/forum/showthread.php?t=38958

'Bookmarks
' http://vbaexpress.com/forum/showthread.php?p=185718