MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old May 23rd, 2002, 03:15 PM   #1
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
Default

I'm developing a program to create PDF's on the fly, but I'm not able to close the Acrobat Window that gets opened (Not by me, but by the process itself)... I couldn't find any API call to do that, is this possible ?
__________________
Regards,

Juan Pablo González
http://www.juanpg.com
Juan Pablo González is offline   Reply With Quote
Old May 23rd, 2002, 04:05 PM   #2
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

Wonder how the process opens it. Perhaps with createobject one can create and terminate the instance as in the following link:

http://forum.planetebook.com/archive/3164.htm

Using the class name (with the reader at least) is not too much fun, it's dynamic, changing with every instance.
__________________
Regards,
Nate Oliver
Microsoft Excel MVP
Nate's Excel Blog
NateO is offline   Reply With Quote
Old May 23rd, 2002, 04:11 PM   #3
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
Default

This is what's happening... you create a PDF basically by printing a document. But then, since i'm using Adobe Distiller, it opens Adobe Writer, and it creates the document just fine... but it creates it in this particular location that I don't want it ! so, I copy it where I want, but then, I want to kill the old (original) file... but I can't ! why ? Adobe is STILL open, and using it ! sucks, right ?

That code from PlanetPDF (I got the other part that I'm using from there too !) looks great, thanks. I do need to join them all after creating them !
__________________
Regards,

Juan Pablo González
http://www.juanpg.com
Juan Pablo González is offline   Reply With Quote
Old May 23rd, 2002, 11:17 PM   #4
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Quote:
On 2002-05-23 15:11, Juan Pablo G. wrote:
This is what's happening... you create a PDF basically by printing a document. But then, since i'm using Adobe Distiller, it opens Adobe Writer, and it creates the document just fine... but it creates it in this particular location that I don't want it ! so, I copy it where I want, but then, I want to kill the old (original) file... but I can't ! why ? Adobe is STILL open, and using it ! sucks, right ?

That code from PlanetPDF (I got the other part that I'm using from there too !) looks great, thanks. I do need to join them all after creating them !
Hi Juan....did you get it to close ??

How have you created the App ??

You could either use the SendMessage function which sends the specified message (control constants) to the window, this calls the window procedure for the window and doesn't return until the window procedure has processed the message so it is in effect synchronous, or
the PostMessage function which posts a message to a thread’s message queue and returns immediately - asyncronous - try using this one.

Nate is correct in that getting the Class name for that you get
a dynamic name everytime
eg Afx:400000:8:148e:0:408f,
Afx:400000:8:148e:0:4757,
Afx:400000:8:148e:0:4727

You can however look for just the partial name Str...
I beleive there has being a thread on this to which I posted.
There were a couple of solutions to this was supplied, I have
amended it here.

You can change it as required.....the sTitle or Caption of the
PDF file is the key.

But Postmsg should do it.
eg.

Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

'// Close window Constant
Const WM_CLOSE = &H10

All you then need is the handle to the window so

call PostMessage PDF_WindowHandle, WM_CLOSE,0,0


Actually, now that I think of it the Html addin has a routine
to get the windows...in this case it maximizes it, all you need
to do is change it to send the WM_CLOSE const instead.

Ay way here is the routine to get the Class name, window handle to that
App and then Close it.


Option Explicit
Option Compare Text

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Const WM_CLOSE = &H10

Private psAppNameContains As String
Private pbFound As Boolean
Private sTitle As String

Public Function AppTitleByStringPart(StringPart As String) As Boolean
Dim lRet As Long
psAppNameContains = StringPart
lRet = EnumWindows(AddressOf CheckForInstance, 0)
AppTitleByStringPart = pbFound
pbFound = False
End Function

Private Function CheckForInstance(ByVal lhWnd As Long, ByVal _
lParam As Long) As Long
Dim lRet As Long
Dim iNew As Integer

If Trim(psAppNameContains = "") Then
CheckForInstance = False
Exit Function
End If

sTitle = Space(255)
lRet = GetWindowText(lhWnd, sTitle, 255)
sTitle = StripNull(sTitle)

If InStr(sTitle, psAppNameContains) > 0 Then
CheckForInstance = False
pbFound = True
Else
CheckForInstance = True
End If

End Function

Private Function StripNull(ByVal InString As String) As String
Dim iNull As Integer
If Len(InString) > 0 Then
iNull = InStr(InString, vbNullChar)
Select Case iNull
Case 0
StripNull = InString
Case 1
StripNull = ""
Case Else
StripNull = Left$(InString, iNull - 1)
End Select
End If
End Function

Sub GetClass()
Dim WndHdl As Long, sWndTitle As String, RetVal As Long, lpClassName As String

sWndTitle = InputBox("Enter at least one word from the Window Title:")

If sWndTitle <> "" Then
AppTitleByStringPart (sWndTitle)
sWndTitle = sTitle
WndHdl = FindWindow(vbNullString, sWndTitle)
lpClassName = Space(256)
RetVal = GetClassName(WndHdl, lpClassName, 256)
MsgBox "Classname for Window Caption" & "[" & sWndTitle & "]" & vbLf & vbLf & _
" = " & Left$(lpClassName, RetVal) & vbCr & _
"WindowHandle:=" & WndHdl
Else
MsgBox "No match found for " & sTitle & ""
End If


PostMessage WndHdl, WM_CLOSE, 0, 0

End Sub





_________________
Kind Regards,
Ivan F Moala From the City of Sails


[ This Message was edited by: Ivan F Moala on 2002-05-23 22:20 ]
Ivan F Moala is offline   Reply With Quote
Old May 24th, 2002, 08:01 AM   #5
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
Default

Thanks Ivan, see ? told you, you know your API !

I'll give it a shot right away... I did find the SendMessage function, but didn't know where to look for the message constant to close the window, how do you know that ? APIGuide doesn't have them, and (obviously) neither AllApi.net (Because they're the same !)
__________________
Regards,

Juan Pablo González
http://www.juanpg.com
Juan Pablo González is offline   Reply With Quote
Old May 24th, 2002, 08:08 AM   #6
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

Another site I've used is

http://www.vbapi.com

Quite a nice site, though it's no longer maintained.
__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien is offline   Reply With Quote
Old May 24th, 2002, 08:27 AM   #7
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Quote:
On 2002-05-24 07:01, Juan Pablo G. wrote:
Thanks Ivan, see ? told you, you know your API !

I'll give it a shot right away... I did find the SendMessage function, but didn't know where to look for the message constant to close the window, how do you know that ? APIGuide doesn't have them, and (obviously) neither AllApi.net (Because they're the same !)
The Const should be list in the WinAPI.txt
All window msg constants start with WM.
In fact it wasn't till I really had a good
look, while playing around that I realised that that was how the conventioning went eg.

Public Const WM_CLOSE = &H10
Public Const WM_ACTIVATE = &H6
Public Const WM_ACTIVATEAPP = &H1C
Public Const WM_PAINT = &HF
Public Const WM_PASTE = &H302
Public Const WM_SETFONT = &H30
Public Const WM_SETFOCUS = &H7
Public Const WM_SETCURSOR = &H20

Winapi.txt...forgot where I got it, But I thought you had VB6, I think it's gets installed with it, although I believe it misses on a lot of other API calls and consts ??

Most Sendmessage API examples post this const
as it's the most common one ie to close a window.

Good luck....wouldn't mind see the code for the PDF file.....sounds handy to have.

__________________
Kind Regards,
Ivan F Moala From the City of Sails
Ivan F Moala is offline   Reply With Quote
Old May 24th, 2002, 08:45 AM   #8
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

I think WinAPI.txt is the one that you need to download from microsoft.

If I recall correctly, the Dan Appleman book has this on the CD and has his own modified API file.
Mark O'Brien is offline   Reply With Quote
Old May 24th, 2002, 08:55 AM   #9
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
Default

Sure ! (About the PDF code)... and it's really cool ! you (will) define which files (Word and Excel) to convert, in which order and where to put it.
__________________
Regards,

Juan Pablo González
http://www.juanpg.com
Juan Pablo González is offline   Reply With Quote
Old May 24th, 2002, 08:59 AM   #10
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Quote:
On 2002-05-24 07:55, Juan Pablo G. wrote:
Sure ! (About the PDF code)... and it's really cool ! you (will) define which files (Word and Excel) to convert, in which order and where to put it.
Hey that sounds GREAT...
__________________
Kind Regards,
Ivan F Moala From the City of Sails
Ivan F Moala is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 02:58 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes