找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 19626|回复: 2

[问题求助] vbs如何实现excel中的选择性粘贴

[复制链接]
发表于 2013-4-17 21:11:01 | 显示全部楼层 |阅读模式
在网上搜索到excel的选择性粘贴的语句,但貌似不能用
AWB.ActiveSheet.Cells.PasteSpecial Paste:=xlValues
这句是选择性粘贴的语句吧......
那我这样用可以不?
--------------------------------------------------------------
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 Paste:=xlValues
    ( 运行后上面这句提示   “缺少语句”,请问哪里出错了)
oWord.Quit
Set oWord = Nothing
Set objDoc = Nothing
Set fso = Nothing
Set oread = Nothing
Set oExcel = Nothing
Set oWb = Nothing
Set xlsheet = Nothing
--------------------------------------------------------------------------------------
我的目的就是想把aa.doc中的表格里的信息提取到aa.xls中,
如果使用 xlsheet.Cells(1,1).PasteSpecial正常,可以复制粘贴,但把word中的一个单元格都复制进来了,所以就想用excel的选择性粘贴来粘贴上文本。
就指点。。。
发表于 2013-5-24 18:49:08 | 显示全部楼层
两个错误:
1、Paste:=xlValues 是 vba 的内部参数赋值方式
2、xlValues 是 excel 的常量,在 vbs 中尚未定义

改下应该就好了:
  1. Const xlPasteAll=-4104
  2. Const xlPasteAllExceptBorders=7
  3. Const xlPasteColumnWidths=8
  4. Const xlPasteComments=-4144
  5. Const xlPasteFormats=-4122
  6. Const xlPasteFormulas=-4123
  7. Const xlPasteFormulasAndNumberFormats=11
  8. Const xlPasteValidation=6
  9. Const xlPasteValues=-4163
  10. Const xlPasteValuesAndNumberFormats=12
  11. '定义 excel 中的各种常量,不定义直接引用数值也可,不过可读性欠佳

  12. Set oWord = CreateObject("Word.Application")
  13. oWord.Visible = False     
  14. Set objDoc = oWord.Documents.Open("c:\aa.doc")
  15. Set oExcel = CreateObject("Excel.Application")
  16. oExcel.Visible = True  
  17. Set oWb = oExcel.Workbooks.Open("C:\aa.xls")
  18. Set xlsheet = oExcel.Worksheets("sheet1")
  19. oWord.ActiveDocument.Tables(3).Cell(3,3).Select
  20. oWord.Selection.Copy
  21. xlsheet.Cells(1,1).PasteSpecial xlPasteValues
  22. oWord.Quit
  23. Set oWord = Nothing
  24. Set objDoc = Nothing
  25. Set fso = Nothing
  26. Set oread = Nothing
  27. Set oExcel = Nothing
  28. Set oWb = Nothing
  29. Set xlsheet = Nothing
复制代码
发表于 2013-7-15 10:54:25 | 显示全部楼层
Set oExcel= CreateObject("Excel.Application")
Set oWb = oExcel.Workbooks.Open("d:\test.xls")
Set oSheet = oWb.Sheets("Sheet1")
oExcel.rows(3).delete
-------------------------------
能告诉下我为什么把test.xls改成*.xls没用啊?
要怎么写才有用?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 13:10 , Processed in 0.017665 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表