我收到了两个不同的Microsoft Word文档,我的病毒扫描程序警告我包含宏.这些应该是简单的文本文件,发送它们的人甚至不知道宏是什么; 他们可能是个错误,但他们可能是恶意感染的迹象.我的OpenOffice.org安装设置根本不加载宏,因为我很少使用它,所以我不关心我的系统的安全性.我希望能够做的是找出那些宏所做的事情,而不会让我的系统暴露于这些宏的任何恶意意图,以便告诉向我发送文件的人是否传播感染.
问题
Declare语句链接到一个DLL,其路径可以在VBA宏中确定试图解决方案
我尝试Declare使用ThisDocument.VBProject.CodeModule.AddFromString(code)从正常目录加载模板时使用的语句动态添加代码,但是当模板在Word\STARTUP中时,它会给出以下错误:
运行时错误'50289':
由于项目受到保护,无法执行操作.
并且当模板在Word\STARTUP中时,将注册表项"HKEY ___ LOCAL_MACHINE\Software\Microsoft\Office\11.0\Word\Security\AccessVBOM"设置为1不会解决此问题
我真的很难找到解决方案.如果有人知道这样做的方法,那就太好了.
我有一个Word文档,其中包含两个嵌入的Excel文件(使用Insert - > Object - > Create From File添加),我希望使用Word VBA进行修改.我已经到了能够打开嵌入文件进行编辑的程度(参见下面的代码),但是我无法处理Excel工作簿,我可以使用它来进行修改并保存嵌入文件.有人有解决方案吗?提前致谢.
Sub TestMacro()
Dim lNumShapes As Long
Dim lShapeCnt As Long
Dim xlApp As Object
Dim wrdActDoc As Document
Set wrdActDoc = ActiveDocument
For lShapeCnt = 1 To 1 'wrdActDoc.InlineShapes.Count
If wrdActDoc.InlineShapes(lShapeCnt).Type = wdInlineShapeEmbeddedOLEObject Then
If wrdActDoc.InlineShapes(lShapeCnt).OLEFormat.ProgID = "Excel.Sheet.8" Then
'This opens the embedded Excel workbook using Excel
wrdActDoc.InlineShapes(lShapeCnt).OLEFormat.Edit
End If
End If
Next lShapeCnt
End Sub
Run Code Online (Sandbox Code Playgroud) 我如何使用VBA以编程方式将图像添加到word文档.
我已经尝试在word文档中添加书签并尝试添加图像,但它总是添加到表单的顶部而不是书签区域.我应该坚持书签还是有其他方式来添加图像?
请参阅下面的代码:
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")
Dim objWdRange As Word.Range
Dim GraphImage As String
Dim shortString As String
shortString = Range("short").Value
GraphImage = "http://xxx.xxxxx.com/xxx/xxx.png?instrument=Image.png"
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("C:\Program Files\My Dropbox\dailystrategy.doc")
Set objWdRange = wrdDoc.Content
With wrdDoc
If wrdDoc.Bookmarks.Exists("shortString ") Then
wrdDoc.Bookmarks("shortString ").Range.Text = shortString
End If
If wrdDoc.Bookmarks.Exists("GraphImage") Then
wrdDoc.Bookmarks("GraphImage").Range.InlineShapes.AddPicture Filename:=GraphImage, LinkToFile:=False, SaveWithDocument:=True
End If
wrdDoc.SaveAs "c:\temp\test.doc"
' close the document
Set wrdDoc = Nothing
Set wrdApp = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用非常简单的单词宏创建Word文档.宏搜索我放置在文本中的书签,然后在该位置添加一个日期,即未来2周.
但是当我从模板创建一个新文档时,我一直没有找到书签.我已经经历了很多次,有时书签就在那里,有时它在那里,但不允许你点击"转到".
我怎样才能让它发挥作用?我在活动中添加了一小段代码,Document_New()但仍然无法报告书签.
我将文档放在rar文件中,因为我的web服务器无法处理.dotm扩展. 文献
我该如何制作,以便在从此模板生成新文档时,新文档的日期提前2周放在2个粗体部分之间?
Sub Two_Weeks_Ahead()
''# Two_Weeks_Ahead Makro
Selection.GoTo What:=wdGoToBookmark, Name:="TwoWeeks"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Dim dt As Date
dt = DateAdd("d", 14, DateTime.Now)
Selection.TypeText Text:=Format(dt, "yyyy-MM-dd")
End Sub
Private Sub Document_New()
Selection.GoTo What:=wdGoToBookmark, Name:="TwoWeeks"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Dim dt As Date
dt = DateAdd("d", 14, DateTime.Now)
Selection.TypeText Text:=Format(dt, "yyyy-MM-dd")
End Sub
Run Code Online (Sandbox Code Playgroud) 我正在尝试在Outlook中创建一个编号列表,并根据顶级列表项操作它.不幸的是,我发现操作列表的唯一方法是通过ListParagraph类型,它可以平等地分解所有列表项(包括子项),而不是对列表中的每个级别具有不同的访问权限.
有没有办法在一个对象中访问列表项及其所有子项?
谢谢.
这是我目前使用的,适用于只有一个级别项目的列表:
While i <= oMeetingWordDoc.Lists(1).ListParagraphs.Count
Set oRange = oMeetingWordDoc.Lists(1).ListParagraphs(i).Range
*Perform actions with oRange
i = i + 1
wend
Run Code Online (Sandbox Code Playgroud)
通过"一级"列表,我的意思是这样的:
通过带有"子项"的列表,我的意思是这样的:
清单项目1
a)项目a
b)项目b
c)项目c
第2项
a)项目a
b)项目b
第3项
a)项目a
简介:我的公司向客户发送信件,并希望我写一个宏来填写已在word文档中设置的不同文本表单字段,因为发送的不同信件之间的数量变化非常有限.我在excel中做过宏,但这是我第一次遇到ms-word宏
问题:我很难通过ms-word找到有效的智能导航.我确实找到了关于向不同方向移动的文章, 这与箭头键非常相似.希望能够深入了解导航word文档的最佳方式.例如,我应该循环移动到正确的1空间,直到找到有意义的东西或者是否有更有效的方法?
问题:是否可以在变量中存储特定的表单位置,或者ms-word是否没有坐标系?
提前致谢!
我有一个宏,可以在我的文档中找到所有'标题1'样式,并在UserForm的ComboBox中列出它们.
我的问题是我正在使用的查找例程也在我要复制的文本之后选择段落标记(),并且正在ComboBox中显示.
如何从字符串中删除它?我试过期运用replace(),更换vbCrLf,vbCr,vbLf,vbNewLine,^p,v,Chr(244)和Asc(244)用"",但一切都没有succeeeded.例如 -
sanitizedText = Replace(Selection.Text, "^v", "")
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助解决这个问题吗?谢谢.
这是我的表格看起来 -

我想自动执行仅使用Office 2007 VBA的Document.Protect保护word文档以进行注释的过程.如果文档还没有保护,这可以正常工作,但是一旦设置了保护,它就会失败.
以下是一个最小的工作示例,显示了我面临的错误(见下文).我在另一台运行Office 2007 SP3的PC上重现了.即使使用空白文档也会出现此问题.
要重现,请在保存新的空白文档后使用以下宏:
Sub ProtectionBugOffice2007()
' Apply a first type of locking to simulate an existing lock
RecentFiles(1).Open
If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect
ActiveDocument.Protect wdAllowOnlyFormFields
ActiveDocument.Close (wdSaveChanges)
' Now do the real test: Lock with our intended protection type
RecentFiles(1).Open
ActiveDocument.Unprotect
ActiveDocument.Protect wdAllowOnlyComments
ActiveDocument.Close (wdSaveChanges)
' Validate!
RecentFiles(1).Open
If ActiveDocument.ProtectionType = wdAllowOnlyComments Then
MsgBox "Success!"
Else
MsgBox "Failure! Should be " & wdAllowOnlyComments & " but is " & ActiveDocument.ProtectionType
End If
ActiveDocument.Close
End Sub …Run Code Online (Sandbox Code Playgroud) 我第一次运行它时,下面的代码运行正常,但是当我需要第二次运行它时,它给了我这个错误:
运行时错误'462':远程服务器计算机不存在或不可用
它不会一直发生,所以我认为它与Word(不)在后台运行有关...?我在这里错过了什么?
Sub Docs()
Sheets("examplesheet").Select
Dim WordApp1 As Object
Dim WordDoc1 As Object
Set WordApp1 = CreateObject("Word.Application")
WordApp1.Visible = True
WordApp1.Activate
Set WordDoc1 = WordApp1.Documents.Add
Range("A1:C33").Copy
WordApp1.Selection.PasteSpecial Link:=False, DataType:=wdPasteRTF, _
Placement:=wdInLine, DisplayAsIcon:=False
Application.Wait (Now + TimeValue("0:00:02"))
WordDoc1.PageSetup.TopMargin = CentimetersToPoints(1.4)
WordDoc1.PageSetup.LeftMargin = CentimetersToPoints(1.5)
WordDoc1.PageSetup.BottomMargin = CentimetersToPoints(1.5)
' Control if folder exists, if not create folder
If Len(Dir("F:\documents\" & Year(Date), vbDirectory)) = 0 Then
MkDir "F:\documents\" & Year(Date)
End If
WordDoc1.SaveAs "F:\documents\" & Year(Date) & "\examplename " & …Run Code Online (Sandbox Code Playgroud)