文件对话框不显示在顶部且不可见 [英] File dialog box not displaying on top and not visable
问题描述
我想选择一个用于Outlook中的电子邮件的信纸,并将其应用到当前的电子邮件中。我有下面列出的代码,如果vba项目管理器没有打开,它的工作效果很好。问题是浏览器仅在顶部显示如果VBA项目
管理器已打开。如果VBA项目未打开,则浏览器显示在outlook后面。
Sub InsertStationery()
'您需要设置对脚本对象的引用
Dim fso As Scripting.FileSystemObject
Dim tsTextIn As Scripting.TextStream
Dim strTextIn As String
Dim strInsert As String
Dim fsoFile As Scripting.File
Dim fsoFldr As Scripting.Folder
Dim dtNew As Date,sNew As String
Dim fDialog As Office.FileDialog
Dim otherObject As Excel.Application
    Dim fdFolder As Office.FileDialog
设置otherObject = New Excel.Application
'otherObject.Visible = False
设置fDialog = otherObject.Application.FileDialog(msoFileDialogFolderPicker)
设置fDialog = Excel.Application.FileDialog(msoFileDialogFilePicker)
  ; 使用fDialog为
'允许用户在对话框中进行多项选择。
.AllowMultiSelect = False
'设置对话框的标题。
.Title ="请选择你想要的文件"
.InitialFileName =" c:\ Users \ Receptionist \ AppData \ Rooaming\Microsoft \ Ontery " b
'清除当前的过滤器,并添加我们自己的过滤器。
.Filters.Clear
.Filters.Add"All Files"," * .htm"
'显示对话框。如果.Show方法返回True,则为
'用户选择了至少一个文件。如果.Show方法返回
'错误,用户点击取消。
如果.Show = True则为
'循环浏览所选的每个文件并将其添加到列表框。
For Each varfile In .SelectedItems
'Me.FileList.AddItem varFile
strfile = varfile
下一个
否则
MsgBox"您在文件对话框中单击了取消。"&
结束如果是
结束
'strFile = enviro& " \ AppData\Roaming\Microsoft \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'read html
设置tsTextIn = fso.OpenTextFile(strfile)
strTextIn = tsTextIn.ReadAll
'使用打开的电子邮件项目¥b $ b 设置objMail = Application.ActiveInspector.CurrentItem
使用objMail
'复制原始邮件正文
strInsert = .HTMLBody
'add文具文件
.HTMLBody = strTextIn
'将原始邮件正文添加回来$
.HTMLBody = .HTMLBody& strInsert
。显示
结束与
End Sub
Hello Kirk,
对话框窗口无法识别其父窗口。您需要指定父窗口句柄或尝试使用Windows API函数将其置于前台。请参阅
SetForegroundWindow 以获取更多信息。
I want to pick a stationery to use for an email in outlook and apply it to the current email. I have the code listed below and it works great other then if the vba project manager is not open. The issue is the Browser only shows on top IF the VBA Project Manager is open. If the VBA project is not open the browser shows behind outlook.
Sub InsertStationery()
' You need to set a reference to the scripting object
Dim fso As Scripting.FileSystemObject
Dim tsTextIn As Scripting.TextStream
Dim strTextIn As String
Dim strInsert As String
Dim fsoFile As Scripting.File
Dim fsoFldr As Scripting.Folder
Dim dtNew As Date, sNew As String
Dim fDialog As Office.FileDialog
Dim otherObject As Excel.Application
Dim fdFolder As Office.FileDialog
Set otherObject = New Excel.Application
'otherObject.Visible = False
Set fDialog = otherObject.Application.FileDialog(msoFileDialogFolderPicker)
Set fDialog = Excel.Application.FileDialog(msoFileDialogFilePicker)
With fDialog
'Allow user to make multiple selections in dialog box.
.AllowMultiSelect = False
'Set the title of the dialog box.
.Title = "Please select the file you want"
.InitialFileName = "c:\Users\Receptionist\AppData\Roaming\Microsoft\Stationery"
'Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "All Files", "*.htm"
'Show the dialog box. If the .Show method returns True, the
'user picked at least one file. If the .Show method returns
'False, the user clicked Cancel.
If .Show = True Then
'Loop through each file selected and add it to the list box.
For Each varfile In .SelectedItems
'Me.FileList.AddItem varFile
strfile = varfile
Next
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
'strFile = enviro & "\AppData\Roaming\Microsoft\Stationery\New Leads Churches.htm"
Set fso = New Scripting.FileSystemObject
'read html
Set tsTextIn = fso.OpenTextFile(strfile)
strTextIn = tsTextIn.ReadAll
'Use open e-mail item
Set objMail = Application.ActiveInspector.CurrentItem
With objMail
' copy the original message body
strInsert = .HTMLBody
' add the stationery file
.HTMLBody = strTextIn
'add the original message body back
.HTMLBody = .HTMLBody & strInsert
.Display
End With
End Sub
Hello Kirk,
The dialog window is not aware of its parent window. You need to specify the parent window handle or try to use Windows API functions for bringing it foreground. See SetForegroundWindow for more information.
这篇关于文件对话框不显示在顶部且不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!