vba可以放服务器上处理文档,当Word Doc位于服务器上时,如何从Excel VBA更改Word Doc中的文本?...

我有一个宏,可以根据单词模板创建实验报告,然后将其保存到远程服务器。在我的Excel工作表中选择一个单元格,运行宏,使用空白模板打开Word实例,并根据所选单元格和其他数据保存文件。我想要做的是编辑空白模板中的标题,并将其更新为实验名称,该实验名称位于所选单元格行的第一列。

以下代码在我从本地文件打开文件时起作用,但在文件位于服务器上时不起作用。

Dim oWord As Object

Set oWord = CreateObject("Word.Application")

oWord.Visible = True

oWord.Activate

' Open a new instance of the ExperimentTemplate and save it

oWord.Documents.Add Template:="ExperimentTemplate", NewTemplate:=False, DocumentType:=0

oWord.ActiveDocument.SaveAs FileName:=fPath & "example.docx", FileFormat:=wdFormatXMLDocument 'fPath is the path to the folder where file will be saved on the server

oWord.ActiveDocument.Close

' Re-open file and change Experiment Name

oWord.Documents.Open FileName:=fPath & "example.docx"

Set oSelection = oWord.Selection

oSelection.Find.Text = "Experiment Name"

oSelection.Find.Replacement.Text = name 'defined as the text in the first cell of the selected column

oSelection.Find.Execute Replace:=wdReplaceAll

oWord.ActiveDocument.Save

oWord.Quit

Set oWord = Nothing

我知道我的代码不是最优雅的,但除非它影响我试图实现的功能,否则我不会担心。任何帮助将不胜感激。这已经破坏了我的头两个星期了!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值