- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 VB.net 中有一些代码,可以循环遍历文档目录 (.docx) 并更新它们。
代码没有问题,只是如果其中有一个文档被视为“源自 Internet”,则代码会停止,因为 Word 默认情况下会在 protected View 中打开它(可见性故意设置为 false)。
现在,我知道如何更改信任中心设置,但我需要我的应用程序在任何人的计算机上运行,而用户(我的客户)不太可能知道如何执行此操作。
有办法解决这个问题吗?
谢谢。
---编辑---
在最近的示例中,我尝试使用代码打开的文件之一已通过 FTP(由我)从外部添加到目录中。因此,当我的代码循环遍历目录中的所有文档时,代码会在该文件处停止,因为它现在“源自互联网”。
我的问题是,一旦打开文档,代码需要继续并编辑文档,但我的代码无法执行此操作,因为它是在“ protected View ”中打开的。由于单词对象设置为不可见,这会导致代码暂停以供使用输入(通常选择编辑文档),但他们看不到它这样做。
不幸的是,手动更改信任中心设置在这里不是一个选项,因为这些代码正在数百台不同的机器上运行,而这些人不愿意自己更改它 - 他们的看法只是我的代码不起作用,
这是我的代码,它循环遍历目录并将图像插入到文档的标题中。我知道这很草率,但我对此很陌生,每天都在学习。我已用“'****这就是我的问题****”标记了问题发生的位置
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim oWrd As Word.Application
Dim oTok As Word.InlineShape
Dim FSO As New Scripting.FileSystemObject
Dim GUID, PRTY As Scripting.Folder
Dim fl As Scripting.File
Dim sSure As MsgBoxResult
Dim p, a, b, x, y, aa As Integer
Dim bln As Boolean
sSure = MsgBox("Are you Sure?", vbYesNo, "Really?")
If sSure = vbNo Then
Exit Sub
End If
For Each GUID In FSO.GetFolder(TextBox1.Text).SubFolders
For Each PRTY In FSO.GetFolder(GUID.Path).SubFolders
For Each fl In FSO.GetFolder(PRTY.Path).Files
a = a + 1
Next
Next
Next
ToolStripStatusLabel1.Text = "Running..."
oWrd = New Word.Application
oWrd.ScreenUpdating = False
oWrd.Visible = False
ToolStripProgressBar1.Value = 0
For Each GUID In FSO.GetFolder(TextBox1.Text).SubFolders
For Each PRTY In FSO.GetFolder(GUID.Path).SubFolders
For Each fl In FSO.GetFolder(PRTY.Path).Files
x = x + 1
If Not fl.Path Like "*\Land Registry\*" Then
If Not fl.Path Like "*\Billing\*" Then
If Not fl.Path Like "*\Attendance Notes\*" Then
If fl.Name Like "*(LH)*" Then
aa = aa + 1
GoTo c
End If
If FSO.FileExists(Split(fl.Path, ".")(0) & " (LH).dot") Then
aa = aa + 1
GoTo c
End If
y = y + 1
'****THIS IS WHERE MY PROBLEM IS****
oWrd.Documents.Open(fl.Path)
'If MS WORD DECIDES THIS DOCUMENT "ORIGINATED FROM THE INTERNET", THE CODE CANNOT RUN PAST THIS POINT DUE TO THE "PROTECTED VIEW" AND THE USER CAN'T SEE IT.
a:
Try
oWrd.Selection.Find.Text = "Dear "
Catch ex As Exception
p = p + 1
If p = 20 Then
MsgBox("Too Many Rertys")
End If
GoTo a
End Try
bln = oWrd.Selection.Find.Execute
If bln = True Then
If CheckBox4.Checked = True Then
If oWrd.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = False Then
b:
Try
oWrd.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True
Catch ex As Exception
oWrd.ActiveWindow.ActivePane.View.ShowAll = True
oWrd.Selection.HomeKey()
oWrd.Selection.Find.Text = "^b"
bln = oWrd.Selection.Find.Execute
If bln = True Then
oWrd.Selection.Delete()
oWrd.ActiveWindow.ActivePane.View.ShowAll = False
Else
MsgBox("oops")
End If
GoTo b
End Try
End If
Else
If oWrd.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True Then
oWrd.ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = False
End If
End If
oWrd.ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekFirstPageHeader
oWrd.Selection.WholeStory()
If oWrd.Selection.InlineShapes.Count > 0 Then
Dim RSLT As VBA.MsgBoxResult
RSLT = MsgBox("HEADER TOKEN DETECTED" & vbNewLine & vbNewLine & "Would you like to continue?", vbYesNo, "WARNING")
If RSLT = MsgBoxResult.No Then
oWrd.Visible = True
Exit Sub
End If
End If
oTok = oWrd.Selection.InlineShapes.AddPicture("http://img.photobucket.com/albums/v353/catfinger/LetterheadToken_zps7f2a4851.png")
oTok.AlternativeText = "replace_Database.OtherTemplate_" & Split(ComboBox1.Text, " ")(0) & ".Content"
If CheckBox2.Checked = True Then
If Not TextBox2.Text = "" Then
If CheckBox3.Checked = True Then
oWrd.Selection.HomeKey()
End If
If CheckBox5.Checked = True Then
oWrd.Selection.EndKey()
End If
For b = 1 To TextBox2.Text
oWrd.Selection.TypeParagraph()
Next
End If
End If
oWrd.ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekMainDocument
If CheckBox8.Checked = True Then
oWrd.ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekFirstPageFooter
Dim footPath As String = IO.Path.GetFullPath(My.Resources.ResourceManager.BaseName)
footPath = footPath.Substring(0, footPath.Length - 39) & "Resources\LetterheadToken.png"
oTok = oWrd.Selection.InlineShapes.AddPicture(footPath)
oTok.AlternativeText = "replace_Database.OtherTemplate_" & ComboBox2.Text & ".Content"
If CheckBox2.Checked = True Then
If Not TextBox3.Text = "" Then
If CheckBox7.Checked = True Then
oWrd.Selection.HomeKey()
End If
If CheckBox6.Checked = True Then
oWrd.Selection.EndKey()
End If
For b = 1 To TextBox2.Text
oWrd.Selection.TypeParagraph()
Next
End If
End If
End If
If CheckBox1.Checked = True Then
oWrd.ActiveDocument.SaveAs2(Split(fl.Path, ".")(0) & " (LH).dot")
Else
oWrd.ActiveDocument.Save()
End If
End If
oWrd.ActiveDocument.Close()
End If
End If
End If
c:
ToolStripStatusLabel1.Text = (x & " of " & a & " (" & y & " updates so far...) / (" & aa & " Skipped)")
ToolStripProgressBar1.Value = (x / a * 100)
Me.Refresh()
Next
Next
Next
ToolStripStatusLabel1.Text = "Finished..."
MsgBox(y & " Letterheads were created out of a possible " & x & ".")
ToolStripStatusLabel1.Text = "Ready..."
End Sub
最佳答案
所以这最终就是我正在寻找的:
要强制将文档置于 protected View 中并从那里进行编辑:
Sub OpenPVThenEdit
ProtectedViewWindows.Open("DOCUMENT PATH HERE")
ProtectedViewWindows(1).Edit
End Sub
------------或-------------
如果您没有打开其他 Word 文档,并且想要检查该文档是否已在 protected View 中打开:
Sub TestForPVw
Documents.Open("DOCUMENT PATH HERE")
If ProtectedViewWindows.Count > 0 Then
ProtectedViewWindows(1).Edit
End If
End Sub
------------或-------------
如果您确实打开了其他 Word 文档并想要检查此特定文档是否已在 protected View 中打开(未经测试):
Sub TestForPVw
Dim dDoc as Document
Set dDoc = Documents.Open("DOCUMENT PATH HERE")
If ProtectedViewWindows.Count > 0 Then
ProtectedViewWindows(dDoc.Name).Edit
End If
End Sub
关于vb.net - 当保护 View 打开时如何使用Word对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26917156/
我有几个问题。我是 Visual Basic 这个领域的新手,所以不要取笑我。 1.) VB.NET之间有什么区别和 VB ? 2.) 我需要为 Windows 开发基本的应用程序。(如记事本)我应该
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我是框架 3.5 的新手。我注意到,在创建 Web 内容表单时,除了 aspx.vb 页面之外,它还会创建一个 aspx.designer.vb 页面。谁能向我解释一下它们之间的区别以及它们的用途吗?
我只是想知道 VB.NET 和 VB 2010 是否相同。 我只是想知道。 最佳答案 VB 2010 是 VB.Net 的最新版本。 Microsoft 在 VB 2005 版本中删除了 VB 的“.
我是框架 3.5 的新手。我注意到,在创建 Web 内容表单时,除了 aspx.vb 页面之外,它还会创建一个 aspx.designer.vb 页面。谁能向我解释一下它们之间的区别以及它们的用途吗?
我正在尝试将 VB 函数移植到 VB.NET,但我无法使该函数正常工作并正确更新。 rFormat = Format(Format(Value, fmt), String$(Len(fmt), "@"
如何在VB中注释多行代码/代码块? 最佳答案 VB 在语言级别上没有这样的构造。它有使用撇号字符的单行注释: ' hello world ' this is a comment Rem this is
我正在使用我在 VB2005 中创建的表单在按下按钮时打开程序,然后在文本字段中显示进程 ID(再次按下按钮时)。当我运行它时,表单将打开程序 (Notepad.exe) 但当我单击按钮查看进程 ID
我正在尝试添加一个从 vb.net 创建的 dll,并且想将其导入到现有的 vb 6 项目中,但它给了我错误“无法添加对指定文件的引用”。 。有人知道如何解决这个问题吗? 最佳答案 需要遵循以下步骤:
我有一个数据 GridView 。右键单击它会显示一个上下文菜单,但它始终位于右上角。我想要它,以便菜单出现在用户右键单击的单元格上。它可能是单元格 1 或单元格 2 或其他。 谢谢福尔坎 最佳答案
我只是在 Visual Studio 2010 中使用 Visual Basic。有人知道我将如何制作“浏览文件夹(或文件)”按钮吗?我对 VB 真的很陌生,我只是在寻找一些简单的帮助:) 最佳答案
这次感到困惑... 最简单的代码行有时可能起作用,有时却没有。首先,我认为问题在于我试图读取DWORD的值,但是由于我可以从某些键读取DWORD值,所以这一定不是问题。现在的问题似乎是,如果 key
我的代码中有此方法: Private Sub Display() Received.AppendText(" - " & RXArray) End Sub 这两个调用之间有什么区别:
我正在创建一个宏程序来记录和回放鼠标和键盘输入。录制效果很好,鼠标播放也一样,但是我在播放键盘输入时遇到了麻烦——特别是在释放之前按住一个键几秒钟。这不等同于重复按键。这是我尝试过的: 技巧 1:Me
我最近刚刚了解了 VB.NET 中静态局部变量的使用,并想知道它在延迟加载属性中的潜在用途。 考虑以下示例代码。 Public Class Foo Implements IFoo End Clas
VB 有一个 C# 没有的特性,在项目级别导入命名空间(我的项目>引用>导入命名空间)。当新人在源代码控制之外检查项目时,我们的自定义导入不包括在内。这个 VB 特定的导入命名空间存储在哪里? 最佳答
我已将我的问题缩小到这个简单的案例,但似乎无法找到发生了什么: 我有两个表单,一个只有一个按钮,另一个是空的。 单击按钮时,form1 隐藏和显示 form2 出现时,form2隐藏,form1再次显
为什么下面的简单代码会失败?无论我使用 LinearGradientMode 的哪个值,这段代码总是用从左到右的渐变填充路径。 graphPath 是在别处创建的 GraphicPath 对象(基本上
我可以多快替换字符串中的字符? 所以这个问题的背景是这样的:我们有几个应用程序通过套接字相互通信并与客户端的应用程序通信。这些套接字消息包含不可打印的字符(例如 chr(0)),需要用预定的字符串(例
如何从任何文件中读取原始字节数组... Dim bytes() as Byte ..然后将该字节数组写回新文件? 我需要它作为一个字节数组来做一些处理。 我目前正在使用: 阅读 Dim fInfo
我是一名优秀的程序员,十分优秀!