计算机名称在word模板中 [英] computer name in a word template

查看:120
本文介绍了计算机名称在word模板中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够确定医生在哪里指示报告。由于医生搬家,但电脑没有。如果我可以将计算机名称放在他们正在使用的单词模板中,我认为可以这样做。文档中的任何位置都可以。
最好在最后或报告页脚/标题。


我听说过类似的问题,但无法找到我想要的答案。



谢谢


解决方案


Randy Robbins,


您可以参考以下示例在Header中添加计算机名称。

 Sub demo1()

Dim HdrText As String
Dim BoldRange As Range
Dim HdrRange As Range


Set HdrRange = ThisDocument.Sections.Item(1).Headers(wdHeaderFooterPrimary).Range
HdrText ="本文件已在计算机名称上编辑:" &安培; Environ("ComputerName")
HdrRange.Text = HdrText

'要添加一些粗体格式,您可以使用下面的代码。如果你不想要任何格式化,你可以删除它。
Set BoldRange = HdrRange.Words(1)
BoldRange.Expand(wdSentence)
BoldRange.Font.Bold = True

End Sub




输出:



您可以参考以下示例在页脚中添加计算机名称。


< pre class ="prettyprint"> Sub demo2()

Dim FtrText As String
Dim BoldRange As Range
Dim FtrRange As Range


设置FtrRange = ThisDocument.Sections.Item(1).Footers(wdHeaderFooterPrimary).Range
FtrText ="此文档在计算机上编辑命名:" &安培; Environ("ComputerName")
FtrRange.Text = FtrText

'要添加一些粗体格式,您可以使用下面的代码。如果你不想要任何格式化,你可以删除它。
Set BoldRange = FtrRange.Words(1)
BoldRange.Expand(wdSentence)
BoldRange.Font.Bold = True

End Sub

输出:




您可以根据自己的要求修改代码。


问候


Deepak


hi, I want to be able to identify where a doctor is dictating a report from. since the doctors move but the computers do not. i think this could be done if i can put the computer name in the word template they are using. Anywhere in the document will work. preferably at the end or a report footer/header.

I have heard of similar questions but cant find the answer i am looking for.

thanks

解决方案

Hi Randy Robbins,

you can refer example below to add computer name in Header.

Sub demo1()

Dim HdrText As String
Dim BoldRange As Range
Dim HdrRange As Range


    Set HdrRange = ThisDocument.Sections.Item(1).Headers(wdHeaderFooterPrimary).Range
    HdrText = "This Document was edited on Computer Named : " & Environ("ComputerName")
    HdrRange.Text = HdrText

    'To add some bold formatting you can use code below. you can remove it if you dont want any formatting.
    Set BoldRange = HdrRange.Words(1)
    BoldRange.Expand (wdSentence)
    BoldRange.Font.Bold = True
    
End Sub


Output:

you can refer example below to add computer name in Footer.

Sub demo2()

Dim FtrText As String
Dim BoldRange As Range
Dim FtrRange As Range


    Set FtrRange = ThisDocument.Sections.Item(1).Footers(wdHeaderFooterPrimary).Range
    FtrText = "This Document was edited on Computer Named : " & Environ("ComputerName")
    FtrRange.Text = FtrText

    'To add some bold formatting you can use code below. you can remove it if you dont want any formatting.
    Set BoldRange = FtrRange.Words(1)
    BoldRange.Expand (wdSentence)
    BoldRange.Font.Bold = True
    
End Sub

Output:

you can modify code as per your requirement.

Regards

Deepak


这篇关于计算机名称在word模板中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆