两个错误:
1、Paste:=xlValues 是 vba 的内部参数赋值方式
2、xlValues 是 excel 的常量,在 vbs 中尚未定义
改下应该就好了:- Const xlPasteAll=-4104
- Const xlPasteAllExceptBorders=7
- Const xlPasteColumnWidths=8
- Const xlPasteComments=-4144
- Const xlPasteFormats=-4122
- Const xlPasteFormulas=-4123
- Const xlPasteFormulasAndNumberFormats=11
- Const xlPasteValidation=6
- Const xlPasteValues=-4163
- Const xlPasteValuesAndNumberFormats=12
- '定义 excel 中的各种常量,不定义直接引用数值也可,不过可读性欠佳
-
- Set oWord = CreateObject("Word.Application")
- oWord.Visible = False
- Set objDoc = oWord.Documents.Open("c:\aa.doc")
- Set oExcel = CreateObject("Excel.Application")
- oExcel.Visible = True
- Set oWb = oExcel.Workbooks.Open("C:\aa.xls")
- Set xlsheet = oExcel.Worksheets("sheet1")
- oWord.ActiveDocument.Tables(3).Cell(3,3).Select
- oWord.Selection.Copy
- xlsheet.Cells(1,1).PasteSpecial xlPasteValues
- oWord.Quit
- Set oWord = Nothing
- Set objDoc = Nothing
- Set fso = Nothing
- Set oread = Nothing
- Set oExcel = Nothing
- Set oWb = Nothing
- Set xlsheet = Nothing
复制代码
|