Results 1 to 8 of 8

Thread: Xbasic to find and activate an excel window

  1. #1
    Member Ton Spies's Avatar
    Real Name
    Ton Spies
    Join Date
    Apr 2002
    Location
    Leeuwarden, The Netherlands
    Posts
    555

    Default Xbasic to find and activate an excel window

    I like to have the opportunity to send some commands to an open NOT ACTIVATED excel window.
    Excel is just opened in a new window besides my other XP windows.

    The story.
    I made a workaroundscript in Xbasic for an unwilling ODBC table from an IBM-AS400.

    I have an ODBC-table-browse and can ONLY give the command: quick export to excel.
    Excel opens and the "browse" now appears in excel
    but as Alpha Five's script is running, excel will loose focus.
    But I don't want to have it in excel but in a ".dbf"

    so by hand:

    - 1. I give focus to excel
    - 2. I save the file to the type ".dbf" with an existing filename.
    - 3. I type "Y" to the Overwrite-prompt and then I want to quit.
    - 4. I give an "Alt-F4" command and say "N" to the "Want to save as new excel version".

    I prefer to use some Xbasic for the commands given by hand.

    Most important now: How can I find the right window (with excel) ?
    So that I then can give these commands in sys_send_keys ("{F12}filename{TAB}D{ENTER}{ENTER}y{%F4}n")

    Who did something like this before?

    Ton

  2. #2
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default RE: Xbasic to find and activate an excel window

    Instead of tring to send keys and such as you are doing, wold this work. You should perform the quick export, save the excel file, then use this function to convert it .dbf. (excelname and newname can be the same)

    FUNCTION excel_convert AS C (excelname AS C, newname AS C )
    Dim xlApp as p
    xlApp = ole.create("Excel.Application")
    xlApp.Workbooks.Open(excelname)
    'xlApp.Visible = .T. 'comment this line out if you don't want to see Excel
    xlapp.DisplayAlerts = .F.
    xlApp.ActiveWorkbook.SaveAs(newname,11) '11 is a constant for .dbf type file
    xlApp.Workbooks.Close()
    xlapp.DisplayAlerts = .T.
    xlApp.Quit()
    END FUNCTION

    'to call the function, use the example on the next line
    'excel_convert("c:\book1.xls","c:\book4.xls")

  3. #3
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default RE: Xbasic to find and activate an excel window

    For saving as .dbf change the usage to

    'to call the function, use the example on the next line
    'excel_convert("c:\book1.xls","c:\somename.dbf")

  4. #4
    "Certified" Alphaholic Marcel Kollenaar's Avatar
    Real Name
    Marcel
    Join Date
    Apr 2003
    Location
    Twente
    Posts
    1,514

    Default RE: Xbasic to find and activate an excel window

    Maybe this information may help too. You can write your information to Excel. In Excel are some macros that do the rest of the handling. The next info is made for Word but you can transform it to Excel.

    Create a macro in Word from Xbasic

    Regards,

    Marcel

  5. #5
    Member Ton Spies's Avatar
    Real Name
    Ton Spies
    Join Date
    Apr 2002
    Location
    Leeuwarden, The Netherlands
    Posts
    555

    Default RE: Xbasic to find and activate an excel window


    Thank you Marcel for your contribution but I am not the Einstein you think. I can handle it all with Xbasic and found the trick to open (and close) excel in silence.

    Groeten

    Ton Spies

  6. #6
    Member Ton Spies's Avatar
    Real Name
    Ton Spies
    Join Date
    Apr 2002
    Location
    Leeuwarden, The Netherlands
    Posts
    555

    Default RE: Xbasic to find and activate an excel window

    Hi Stan,

    Thank you for your Xbasic code. It really pointed me in a good direction.
    I discovered that when you do a quick export to excel, the file is written as “same-filename.xls” to the map “temp” in the “documents and settings -area”.
    After that, excel is started and opened with the just written .xls-file.
    Since I know how and where the file is saved, I can just close excel.
    I have to find out the aliasnames of the system to complete it nicely and make it portable.

    The trick that worked for me:
    1: open excel with Xbasic .
    2: export to excel.
    3: close excel.

    Regards

    Ton Spies



    For someone who wants the details:
    I used an oninitevent on a form.

    'Toggle Form/Browse mode in current form.
    ‘In that browse I only have the fields I need.
    topparent.Toggle_FormBrowse()

    ‘Inline Basic Open excel
    Dim xlApp as p
    xlApp = ole.create("Excel.Application")

    ‘action scripting - in Xbasic: topparent.quick_export()
    quick export to excel

    ‘Inline Basic
    xlapp.DisplayAlerts = .F.
    xlApp.Workbooks.Close() ‘may be don’t need this line but as displayAlerts is .F. I can check it later.
    xlapp.DisplayAlerts = .T.
    xlApp.Quit()

    ‘action scripting
    close form/browse - in Xbasic parentform.close()


    This are the steps but also you can bring it together in one inline xbasic action.

  7. #7
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default RE: Xbasic to find and activate an excel window

    "alias names" - do you mean?

    file.temp_path_get()

  8. #8
    Member Ton Spies's Avatar
    Real Name
    Ton Spies
    Join Date
    Apr 2002
    Location
    Leeuwarden, The Netherlands
    Posts
    555

    Default RE: Xbasic to find and activate an excel window

    Stan,

    That is exactly what I need.
    Never needed before. Can polish my Xbasiccode.
    Thank you!

    Ton

Similar Threads

  1. Find By Key Window
    By Phil Rolf in forum Alpha Five Version 5
    Replies: 3
    Last Post: 07-10-2003, 05:51 AM
  2. Activate an Object - Won't let me choose window
    By Charlain in forum Alpha Five Version 5
    Replies: 2
    Last Post: 05-28-2003, 11:38 AM
  3. Xbasic to Activate Drop Down
    By forskare in forum Alpha Five Version 5
    Replies: 14
    Last Post: 04-26-2003, 07:47 AM
  4. Control Window Bar through Xbasic?
    By French in forum Alpha Five Version 5
    Replies: 2
    Last Post: 12-05-2002, 08:32 AM
  5. Find Record With Xbasic
    By Phil Rolf in forum Alpha Five Version 4
    Replies: 5
    Last Post: 07-06-2001, 06:19 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •