Nick,
Sorry for the long delay, I've been out of the office for the last three days.
Here is a bit of documentation on ShellExecuteA, that you might want to breeze through.
Anyway, I forgot this was a VBA forum when I posted my bit for Linux/Unix type systems.
So, to make a comprehensive windows solution (I am using Excel for testing), what I did was create a "Module" named "Code Test", which contained my test code, as follows:
And then, I created a "Class Module" with the actual launch code, as follows:
IMPORTANT: the first is a "Module", and the second a "Class Module".
Then, in the "Immediate" window of the VBA interface window, I typed the following to demonstrate my code launch.
I sure hope this helps.
Luck!
Sorry for the long delay, I've been out of the office for the last three days.
Here is a bit of documentation on ShellExecuteA, that you might want to breeze through.
Anyway, I forgot this was a VBA forum when I posted my bit for Linux/Unix type systems.
So, to make a comprehensive windows solution (I am using Excel for testing), what I did was create a "Module" named "Code Test", which contained my test code, as follows:
Code:
''==================================================================== ''==================================================================== ''==================================================================== '' '' Code Test '' Module with various prepared code tests and use examples '' ''==================================================================== ''==================================================================== ''==================================================================== Option Compare Database Option Explicit ''==================================================================== ''==================================================================== ''==================================================================== Public Sub TEST_showPDF() Dim wi As Object Set wi = New [Windoze Interface] Call wi.showPDF("C:\tmp\IRON File Systems (vijayan-thesis).pdf") End Sub '===================================================================== '===================================================================== '=====================================================================
And then, I created a "Class Module" with the actual launch code, as follows:
Code:
''==================================================================== ''==================================================================== ''==================================================================== '' '' Windoze Interface '' Code to interface to µsWindows DLLs '' ''==================================================================== ''==================================================================== ''==================================================================== Option Compare Database Option Explicit ''==================================================================== ''==================================================================== ''==================================================================== Private Type Body database As DAO.database ''--database object databaseFile As String ''--local database file EOL As String ''--end of line lastPDF As String ''--last launched PDF file [diagnostic] End Type Private Const moduleName = "Windoze Support" ''==================================================================== ''==================================================================== ''==================================================================== Private this As Body ''==================================================================== ''==================================================================== ''==================================================================== Private Declare Function ShellExecute _ Lib "shell32.dll" _ Alias "ShellExecuteA" _ (ByVal hwnd As Long, _ ByVal lpOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long ''==================================================================== ''==================================================================== ''==================================================================== Private Sub Class_Initialize() Set this.database = Application.CurrentDb this.databaseFile = this.database.name this.EOL = VBA.vbCrLf 'ASCII.CRLF this.lastPDF = "<invalid>" End Sub Private Sub Class_Terminate() 'MsgBox ("Terminating module: " & moduleName) End Sub ''==================================================================== ''==================================================================== ''==================================================================== Property Get databaseFile() As String '' '' accessor for this.databaseFile '' databaseFile = this.databaseFile End Property Property Let databaseFile(ByVal value As String) '' '' accessor for this.databaseFile '' this.databaseFile = value End Property Property Get lastPDF() As String lastPDF = this.lastPDF End Property ''==================================================================== ''==================================================================== ''==================================================================== Public Sub showPDF(ByVal fileName As String) '' '' shows the given PDF file using acrobat '' '' inputs: '' fileName - fully qualified file name to show '' (ex: C:/tmp/my.PDF) '' raises: '' true - unqualified success '' false - otherwise '' ''--local variables and definitions Dim pdf As String Dim run As Boolean Dim seResult As Long ''--initialize pdf = fileName run = True ''--slight diagnostic here... this.lastPDF = fileName ''--attempt liftoff If (run) Then seResult = ShellExecute(0, "OPEN", pdf, "", "", 0) If (32 >= seResult) Then run = False Err.Raise 0, moduleName, "ShellExecute failed with code: " & seResult End If End If ''--end of compilation unit with implicit return End Sub ''==================================================================== ''==================================================================== ''====================================================================
Then, in the "Immediate" window of the VBA interface window, I typed the following to demonstrate my code launch.
Code:
CALL [Code Test].TEST_showPDF
Luck!
Comment