I've read the SDK documentation and a the various VBA threads on this board, but I haven't found an answer to what seems like should be an easy question. I am writing a simple VBA macro (MS Outlook) that I want to behave as follows: user clicks a "Save Email" button, the button opens an Everything search window (filtered to folders only), user selects a folder, the selected folder's path is passed to a variable in the VBA script, which then runs to save the email in the path selected. However, I can't seem to figure out how to open the search window. What am I missing?
Thanks for your help!
Call Everything prompt from VBA
Re: Call Everything prompt from VBA
What does your current VBA code look like? (Please post)
Re: Call Everything prompt from VBA
Sure, here it is:
My Everything functions are stored in a separate module called "Everything":
Code: Select all
Sub SaveSelectedEmail()
' Set variables
Dim ns As Outlook.NameSpace
Dim inbox As Outlook.MAPIFolder
Dim item As Outlook.MailItem
Dim strFileName As String
Dim xSelection As Outlook.Selection
Dim xFolderPath As String
Dim oTopic As String
Dim strFileExists As String
Set xSelection = Outlook.Application.ActiveExplorer.Selection
Set item = xSelection.item(1)
''------EVERYTHING------
'[EVERYTHING STUFF GOES HERE]
'[Should call an Everything prompt and then pass the filepath results back as "xFolderPath"]
''------End------
oTopic = InputBox("VERY briefly, what is the topic of this message? E.g. 'Lease Termination'", "Topic")
' Set namespace
Set ns = Application.GetNamespace("MAPI")
' Get inbox folder
Set inbox = ns.GetDefaultFolder(olFolderInbox)
' Loop through all mail items
' Set filename
strFileName = xFolderPath & VBA.Format(item.ReceivedTime, "yyyy.mm.dd", vbUseSystemDayOfWeek) & " - " & item.SenderName & " - " & oTopic & ".msg"
' Check if this filename already exists
strFileExists = Dir(strFileName)
If strFileExists <> "" Then
MsgBox ("File with this name already exists. Try again with a different topic description.")
Else
' Save mail item to file system
item.SaveAs strFileName, olMSG
End If
EndSub:
Set item = Nothing
Set strFileExists = Nothing
End Sub
Code: Select all
Option Explicit
'Note: sample copied from https://www.voidtools.com/support/everything/sdk/visual_basic/
'Replaced for VBA usage
' - UINT32 with LONG
' - UINT64 with LARGE_INTEGER
' - INTPtr with LONGPtr
' - System.Text.StringBuilder with String
' - System.DateTime with String
' - filename.Capacity with filesize
Private Type LARGE_INTEGER
lowpart As Long
highpart As Long
End Type
Public Declare PtrSafe Function Everything_SetSearchW Lib "C:\SDK\Everything32.dll" (ByVal ins As LongPtr) As Long
Public Declare PtrSafe Function Everything_SetRequestFlags Lib "C:\SDK\Everything32.dll" (ByVal dwRequestFlags As Long) As Long
Public Declare PtrSafe Function Everything_QueryW Lib "C:\SDK\Everything32.dll" (ByVal bWait As Integer) As Integer
Public Declare PtrSafe Function Everything_GetNumResults Lib "C:\SDK\Everything32.dll" () As Long
Public Declare PtrSafe Function Everything_GetResultFileNameW Lib "C:\SDK\Everything32.dll" (ByVal index As Long) As LongPtr
Public Declare PtrSafe Function Everything_GetLastError Lib "C:\SDK\Everything32.dll" () As Long
Public Declare PtrSafe Function Everything_GetResultFullPathNameW Lib "C:\SDK\Everything32.dll" (ByVal index As Long, ByVal ins As LongPtr, ByVal size As Long) As Long
Public Declare PtrSafe Function Everything_GetResultSize Lib "C:\SDK\Everything32.dll" (ByVal index As Long, ByRef size As LARGE_INTEGER) As Integer 'size UInt32
Public Declare PtrSafe Function Everything_GetResultDateModified Lib "C:\SDK\Everything32.dll" (ByVal index As Long, ByRef ft As LARGE_INTEGER) As Integer 'ft UInt64
Public Const EVERYTHING_REQUEST_FILE_NAME = &H1
Public Const EVERYTHING_REQUEST_PATH = &H2
Public Const EVERYTHING_REQUEST_FULL_PATH_AND_FILE_NAME = &H4
Public Const EVERYTHING_REQUEST_EXTENSION = &H8
Public Const EVERYTHING_REQUEST_SIZE = &H10
Public Const EVERYTHING_REQUEST_DATE_CREATED = &H20
Public Const EVERYTHING_REQUEST_DATE_MODIFIED = &H40
Public Const EVERYTHING_REQUEST_DATE_ACCESSED = &H80
Public Const EVERYTHING_REQUEST_ATTRIBUTES = &H100
Public Const EVERYTHING_REQUEST_FILE_LIST_FILE_NAME = &H200
Public Const EVERYTHING_REQUEST_RUN_COUNT = &H400
Public Const EVERYTHING_REQUEST_DATE_RUN = &H800
Public Const EVERYTHING_REQUEST_DATE_RECENTLY_CHANGED = &H1000
Public Const EVERYTHING_REQUEST_HIGHLIGHTED_FILE_NAME = &H2000
Public Const EVERYTHING_REQUEST_HIGHLIGHTED_PATH = &H4000
Public Const EVERYTHING_REQUEST_HIGHLIGHTED_FULL_PATH_AND_FILE_NAME = &H8000
Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Public Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Declare PtrSafe Function FileTimeToSystemTime Lib "kernel32" (ByRef ft As LARGE_INTEGER, lpSystemTime As SYSTEMTIME) As Long
Private Declare PtrSafe Function SystemTimeToTzSpecificLocalTime Lib "kernel32" (ByVal tzi As LongPtr, lpst As SYSTEMTIME, lplt As SYSTEMTIME) As Long
Private Declare PtrSafe Function SystemTimeToVariantTime Lib "OLEAUT32.DLL" (lpSystemTime As SYSTEMTIME, vtime As Date) As Long
Re: Call Everything prompt from VBA
Thanks for posting, tanko.
On second thought: the SDK won't help you much here. It is meant to query the Everything database and do something with the results you get back from that, like creating your own list to present and to select from.
Firing up "regular" Everything is definitely possible, but the SDK has no way to get to the folder that was selected (at least: to my best of knowledge).
(A slightly modified) JumpToFolder -- which you are already aware of as you posted in it's thread -- might better fit your needs.
Or Listary, which has more or less the same functionality aboard.
On second thought: the SDK won't help you much here. It is meant to query the Everything database and do something with the results you get back from that, like creating your own list to present and to select from.
Firing up "regular" Everything is definitely possible, but the SDK has no way to get to the folder that was selected (at least: to my best of knowledge).
(A slightly modified) JumpToFolder -- which you are already aware of as you posted in it's thread -- might better fit your needs.
Or Listary, which has more or less the same functionality aboard.
Re: Call Everything prompt from VBA
Yup, I started with JumpToFolder, but I'm stuck on the right click launch method. I'm writing this macro for a tech-skeptical user base (lawyers in my law firm) and I need to make it as painless as possible or it simply will not be used. Hence I'm trying to launch the everything window on button click and then pass the resulting filepath back to the macro.
I was thinking of calling the Everything search via a shell command in VBA, but I can't think of a way to make it pass the filepath back.
I have been trying out listary, but so far it's not quite right for this application for a couple of reasons.
I was thinking of calling the Everything search via a shell command in VBA, but I can't think of a way to make it pass the filepath back.
I have been trying out listary, but so far it's not quite right for this application for a couple of reasons.
Re: Call Everything prompt from VBA
Is it possible to change the JumpToFolder code so that it runs the StartEverything function when the SaveAs dialog or the Folder Picker dialog appears? I looked at the AHK code and it seems like it might be possible, but I'm extremely unfamiliar with AHK, and a novice coder generally.
Re: Call Everything prompt from VBA
my email:xiaoyaocode
----
@ 163.com
maybe you need get search result ,and show file save dialog
----
@ 163.com
maybe you need get search result ,and show file save dialog