LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Macro launch - Button vs Manual launch , has different result

Wayne wrote:
Tim,
I tried your suggestion. It almost worked.
On the file name prompt I got "YC:\Test\mac1.pdf"
So it seems the keys are sent in the wrong order ?
I took out the Y from the macro & it now works. But how do I automate
this ?

Wayne


Another approach that I've found to work very well is to write the filename
to acrobat's section of the registry and to acrobat's ini files. It seems to
need this belt-and-braces approach because of different versions. The print
driver will then pick up the filename and not bother you with dialog


Option Explicit

Private Declare Function GetSystemDirectory Lib "kernel32" Alias _
"GetSystemDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long

Private Declare Function WritePrivateProfileString Lib "kernel32" Alias _
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, ByVal lpString As Any, _
ByVal lpFileName As String) As Long

Private Declare Function GetWindowsDirectory Lib "kernel32" Alias _
"GetWindowsDirectoryA" (ByVal lpBuffer As String, _
ByVal nSize As Long) As Long

Sub test()
WriteToINI Application.WorksheetFunction.Substitute(ThisWorkb ook.Name, _
".xls", ".pdf")
End Sub

Sub WriteToINI(strSaveAsFileName As String)
'================================================= ==================
'= Procedu sWriteToINI =
'= Type: Private Subprocedure =
'= =
'= Purpose: Writes a filename to both the registry and the =
'= Acrobat.ini file. This is picked up by the =
'= PDFWriter print driver to be used as a filename =
'= for the printed document. =
'= REQUIRES A REFERENCE SET TO THE WINDOWS SCRIPTING =
'= HOST OBJECT MODEL LIBRARY. =
'= Parameters: strSaveAsFileName - String - The FULL name of the =
'= file to print to. =
'= Returns: Nothing =
'= =
'= Version: Date: Developer: Action: =
'=---------|---------|---------------|-----------------------------=
'= 1.0.0 |22-Feb-00| Rob Bruce | Created =
'================================================= ==================

Const REG_ROOT As String = _
"HKEY_CURRENT_USER\Software\Adobe\Acrobat PDFWriter\"

Dim strBuffer As String * 255
Dim strSysDir As String
Dim lngLen As Long
Dim lngRet As Long

Dim objWShell As IWshRuntimeLibrary.WshShell

' New Windows scripting host object.

Set objWShell = New IWshRuntimeLibrary.WshShell


Dim strIniFileName As String

' Use the WSH to write to the registry...
objWShell.RegWrite REG_ROOT & "PDFFileName", strSaveAsFileName

' Write to the ini file...

' Get the location of the system directory...
lngLen = Len(strBuffer)
lngRet = GetSystemDirectory(strBuffer, lngLen)
strSysDir = Left(strBuffer, lngRet) & "\"

' Establish the full name of the ini file...
strIniFileName = strSysDir & "pdfwritr.ini"

' Write the value to the file...
lngRet = WritePrivateProfileString("Acrobat PDFWriter", _
"PDFFileName", """" & strSaveAsFileName & """", _
strIniFileName)

' Get the location of the windows directory...
lngLen = Len(strBuffer)
lngRet = GetWindowsDirectory(strBuffer, lngLen)
strSysDir = Left(strBuffer, lngRet) & "\"

' Establish the full name of the ini file...
strIniFileName = strSysDir & "__pdf.ini"

' Write the value tot he file...
lngRet = WritePrivateProfileString("Acrobat PDFWriter", _
"PDFFileName", """" & strSaveAsFileName & """", _
strIniFileName)
End Sub

--
Rob

http://www.asta51.dsl.pipex.com/webcam/:




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Launch of Macro Daren Excel Discussion (Misc queries) 1 March 20th 07 08:10 PM
Is it possible to make a Button on a tool bar to launch an Add-in Wolf Excel Discussion (Misc queries) 1 June 24th 05 12:13 AM
button to launch my userform JasonSelf[_6_] Excel Programming 2 January 26th 04 04:11 PM
Can you use an IF statement to launch a macro? ian123[_34_] Excel Programming 3 January 3rd 04 12:38 AM
Can I launch the Calendar Control from a Comand Button kathryn Excel Programming 2 November 12th 03 04:25 PM


All times are GMT +1. The time now is 01:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"