2014-02-18 26 views
0

对于一个项目,我必须生成许多带有单独性能报告的单词文档。我已经有了创建这些单独报告的宏。我现在想要的是一个宏,它使用创建的标签的值(例如,我希望文档具有标签名称“username”),该标签位于文档中。我担心我无法提供代码,因为我没有比“另存为”命令更容易(这很容易)。提前致谢。将新文档作为标签名称保存在单词VBA中

+0

“标签名称”是什么意思?你能展示一个它的屏幕截图吗? –

+0

无法发布图像,但我害怕。这里是链接:(http://imageshack.com/a/img853/2126/nc1j.jpg)。为了隐私目的而删除数据。希望这可以让你更清楚。为了方便地使用Word文档中的Excel表单中的数据(我可以轻松地引用这些标签),我制作了标签。 –

回答

0

如果我理解正确,您希望使用Userform中的标签标题生成文件名,然后将文档另存为文件名?

我会假设,然后您将标签标题从您的模块传递给用户窗体。如果是这种情况,那么您只需将Label Caption字符串添加到一起,然后使用ActiveDocument.SaveAs。见下图:

Sub SomeSub() 


Dim NewFileName As String 


'Do something 

'Do something else 

'Create and send labels 

'Now you would have created the captions for your labels 
'and then sent them to the labels 

'Just add the various captions 

EmailKontact = "[email protected]" 

Code = "2323" 

CaptureDate = "2015.09.21" 

NewFileName = EmailKontact & Code & CaptureDate 

'For this example 
'NewFileName is then = [email protected] 

'if you want to save it somewhere specific then you can add 
'the folder paths to the NewFileName otherwise is will save it to My Documents 

ActiveDocument.SaveAs (NewFileName) 


End Sub 

你也可以插入此代码在您的用户窗体CommandButton标签“另存为”,然后它会为ActiveDocument

相关问题