输入2007版本的文档名称时 提示找不到该文档,请问应该怎么修改(问题出在第四行Documents.Open处)?
Sub 数据复制()
Dim Filename As String
Filename = InputBox("请输入要打开的文件名", "数据复制", "C:\Users\Administrator\Desktop\")
Documents.Open Filename:=Filename
Selection.WholeStory
Selection.Copy
Windows("新建 Microsoft Office Word 文档").Activate
Selection.PasteAndFormat (wdPasteDefault)
ActiveDocument.Save
Documents(Filename).Activate
ActiveWindow.Close
End Sub
VBA word 以下代码是实现将多个文档的内容复制到一个文档中,但是只可以复制97-03版本的word文档内容
答案:2 悬赏:60 手机版
解决时间 2021-01-23 17:47
- 提问者网友:暮烟疏雨之际
- 2021-01-23 01:56
最佳答案
- 五星知识达人网友:过活
- 2021-01-23 02:57
随便创建个新的word,修改下inputbox那里的路径
黏贴代码就可以用了
Sub 数据复制()
Dim fName As String
Dim Doct As Document
Set Doct = ThisDocument
fName = InputBox("请输入要打开的文件名", "数据复制", "D:\test\333.docx")
Documents.Open Filename:=fName
Selection.WholeStory
Selection.Copy
Doct.Activate
Selection.PasteAndFormat (wdPasteDefault)
ActiveDocument.Save
Documents(fName).Close False
End Sub
黏贴代码就可以用了
Sub 数据复制()
Dim fName As String
Dim Doct As Document
Set Doct = ThisDocument
fName = InputBox("请输入要打开的文件名", "数据复制", "D:\test\333.docx")
Documents.Open Filename:=fName
Selection.WholeStory
Selection.Copy
Doct.Activate
Selection.PasteAndFormat (wdPasteDefault)
ActiveDocument.Save
Documents(fName).Close False
End Sub
全部回答
- 1楼网友:空山清雨
- 2021-01-23 03:24
vba代码如下:
sub addstr()
dim mydialog as filedialog, ofile as variant, odoc as document
set mydialog = application.filedialog(msofiledialogfilepicker)
with mydialog
.filters.clear
.filters.add "所有 word 文件", "*.doc", 1
.allowmultiselect = true
if .show <> -1 then exit sub
for each ofile in .selecteditems
set odoc = documents.open(filename:=ofile, visible:=false, passworddocument:=oldpw)
with odoc
.content.insertbefore "这是加入的文本" & vbcr
.close true '关闭文档
end with
next ofile
end with
end sub
说明:使用该方法的好处是灵活,不用指定固定的目录来搜寻目标文档,直接运行代码,会自动弹出选择目录或哪些文档的对话框,非常方便。只需修改要加入的内容即可。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯