Announcement

Collapse

Maintenance

The forum could be offline for 30-60 minutes in the very near future for maintenance (said 3pm Pacific). I was behind on getting this notice. I do apologize.
See more
See less

Opening a saved file with Excell(or any other EXE) with code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Opening a saved file with Excell(or any other EXE) with code

    I have created a .csv file with my code in my .EXE.

    If I dbl click it, Excell will open it and everything is great. How can avoid the dbl click?

    ie, how can i tell Excell "open MyFile.csv"


    PS. does anyone know how to save the FORMULAS from excell to a text file so that my EXE can create a .csv file with them in it?

    ------------------
    Kind Regards
    Mike

  • #2
    I haven't tried it, but have you tried shelling to excel?

    Ie.

    SHELL ExcelPath$ + "EXCEL.EXE MYFILE.CSV", 1



    ------------------
    Bernard Ertl
    Bernard Ertl
    InterPlan Systems

    Comment


    • #3

      Mike,

      I have some VB code that creates an XLS Excel spreadsheet (BIFF 2.1)
      format. You could port that code to PB. However, it does not
      do fomulas. It can be found at:
      http://www.planetsourcecode.com/xq/A...s/ShowCode.htm



      ------------------
      Paul Squires
      mailto:[email protected][email protected]</A>
      Paul Squires
      FireFly Visual Designer (for PowerBASIC Windows 10+)
      Version 3 now available.
      http://www.planetsquires.com

      Comment


      • #4
        Thanks Paul, I will look at the code tomorrow.

        The first 59 rows (64Columns wide) are all formula
        (The next 2000 lines are data)

        I send formula in a .csv file as "=myfomula".

        Is it possible to do the same thing with your code?

        ------------------
        Kind Regards
        Mike

        Comment


        • #5
          On my site IN the helpfile, you can find code to find an app by extension.
          In this case WORD.

          A slight rebuild for you..


          ------------------
          hellobasic

          Comment


          • #6
            Mike,

            Unfortunately not. You can not save formulas with my Excel code.
            I have tried to figure out how to parse and save them in the correct
            format but it is over my head.



            ------------------
            Paul Squires
            mailto:[email protected][email protected]</A>
            Paul Squires
            FireFly Visual Designer (for PowerBASIC Windows 10+)
            Version 3 now available.
            http://www.planetsquires.com

            Comment


            • #7
              Bern,

              The Shell works but only if MyFile.csv is in the default folder (My Documents) when excell boots up.

              After much experimenting I cant find a way to tell Excell to look in another folder. any ideas?

              If all three files are in My Documents, then a new instance of excell is launched and all 3 files are opend in that one new instance.

              SHELLResult = SHELL("C:\Program Files\Microsoft Office\Office\Excel.exe Temp1.csv Temp2.csv Temp3.csv", 1)


              ------------------
              Kind Regards
              Mike

              Comment


              • #8
                I haven't tried it, but I think something like:

                Code:
                SHELLResult = SHELL( ExcelPath$ + "Excel.exe " + File1Path$ + "Temp1.csv " + File2Path$ + "Temp2.csv " + File3Path$ + "Temp3.csv", 1)
                should work. Of course this assumes that you can find and assign the full
                directory paths for the files to the File#Path$ variables...



                ------------------
                Bernard Ertl
                Bernard Ertl
                InterPlan Systems

                Comment


                • #9
                  Long File Name (LFN) paths may need to be enclosed in double quotes, ie:
                  Code:
                  ExcelPath$ = "C:\Program Files\Office 2000\Excel\"
                  SHELLResult = SHELL( ExcelPath$ + "Excel.exe """ + File1Path$ + "Temp1.csv"" """ + _
                      File2Path$ + "Temp2.csv"" """ + _
                      File3Path$ + "Temp3.csv""", 1)

                  ------------------
                  Lance
                  PowerBASIC Support
                  mailto:[email protected][email protected]</A>
                  Lance
                  mailto:[email protected]

                  Comment


                  • #10
                    Use ShellExecute("open",...). Then you dont need the Excel-path.

                    Regards
                    Peter

                    ------------------
                    [email protected]
                    www.dreammodel.dk

                    Comment


                    • #11
                      Originally posted by Mike Trader:
                      Bern,

                      The Shell works but only if MyFile.csv is in the default folder (My Documents) when excell boots up.

                      After much experimenting I cant find a way to tell Excell to look in another folder. any ideas?

                      If all three files are in My Documents, then a new instance of excell is launched and all 3 files are opend in that one new instance.

                      SHELLResult = SHELL("C:\Program Files\Microsoft Office\Office\Excel.exe Temp1.csv Temp2.csv Temp3.csv", 1)


                      I use this function to locate and invoke the default open application for an extension:

                      FUNCTION DISPLAYFILE (myfile AS STRING) AS LONG
                      LOCAL retval AS LONG
                      LOCAL hkey AS LONG
                      LOCAL opendialog AS ASCIIZ * 256
                      LOCAL extension AS ASCIIZ * 256
                      LOCAL readercmd AS ASCIIZ * 256
                      extension = "." & PARSE$(myfile,".",-1)
                      'Get Open Command Line from registry
                      retval = RegOpenKeyEx(%HKEY_CLASSES_ROOT,extension,0,%key_query_value,hkey)
                      retval = regqueryvalueex(hkey,"",0,%reg_sz,opendialog,256)
                      retval = regclosekey(hkey)
                      extension = opendialog & "\SHELL\OPEN\command"
                      retval = RegOpenKeyEx(%HKEY_CLASSES_ROOT,extension,0,%key_query_value,hkey)
                      retval = regqueryvalueex(hkey,"",0,%reg_sz,readercmd,256)
                      retval = regclosekey(hkey)
                      REPLACE "%1" WITH myfile IN readercmd
                      retval = SHELL(readercmd)
                      END FUNCTION




                      ------------------
                      Check out my free software at http://www.lexacorp.com.pg

                      Comment


                      • #12
                        Dear Stuart,

                        you Live In Papua New Guinea!? cool. Can I come visit?

                        Thx for your function. could you tell me how to use tho pls?

                        If I send it MyFile.csv it launches excell ok but then how would you go about getting excell to open MyFile.csv?

                        ------------------
                        Kind Regards
                        Mike

                        Comment


                        • #13
                          Lance,

                          That worx, thx.

                          The only thing is that it looks like excel is in different folders depending on the version etc and if it came with office etc etc.

                          For portability, is there some way to determine ExcelPath$ in the code?

                          ------------------
                          Kind Regards
                          Mike

                          Comment


                          • #14
                            You dont need ExcelPath! Use ShellExecute...it is precisely the same as double clicking...

                            Code:
                            	ShellExecute 0,"open", "P:\psp\PBDLL60\Projects\test\test.csv ", byval 0,byval 0, %SW_SHOWNORMAL
                            Regards
                            Peter

                            ------------------


                            [This message has been edited by Peter P Stephensen (edited March 02, 2001).]
                            [email protected]
                            www.dreammodel.dk

                            Comment


                            • #15
                              Someone missed my post i guess?

                              The code DOES retrieve the fileversion path eand exe etc..


                              ------------------
                              hellobasic

                              Comment


                              • #16
                                Yes, you can use ShellExecute().

                                Alternatively, since you are wanting to open a file that already exists on disk, you can use FindExecutable() to get the path and filename of the associated application for a given file type, then simply use SHELL to launch the app with the filename as a parameter (per above).
                                Code:
                                #COMPILE EXE
                                #INCLUDE "WIN32API.INC"
                                 
                                FUNCTION PBMAIN
                                    DIM ExeName AS ASCIIZ * %MAX_PATH
                                    DIM File$, Folder$, Result AS LONG
                                
                                    ' Create the file to ensure the API will succeed
                                    File$ = "FILENAME.XLS"
                                    Folder$ = "C:\"
                                    OPEN Folder$ + File$ FOR OUTPUT AS #1
                                    CLOSE #1
                                 
                                    Result = FindExecutable(BYCOPY File$, BYCOPY Folder$, ExeName)
                                    MSGBOX "SHELL """+ ExeName + " " + File$ + """"
                                 
                                    ' Kill the temp file we used to explore this API
                                    KILL Folder$ + File$
                                END FUNCTION

                                ------------------
                                Lance
                                PowerBASIC Support
                                mailto:[email protected][email protected]</A>
                                Lance
                                mailto:[email protected]

                                Comment


                                • #17
                                  Edwin, I would love to check out your site and your example. Whats the URL?

                                  Lance, thx for the example. I would never have figured out the BYVAL thing or known that the returned:
                                  pointer to buffer for string for executable file
                                  is converted to a string by declaring the name as ASCIIZ!

                                  One problem tho, It turns out I have 2 versions of excel, 97 and 2000. I want to shell to the 2000 ver because it can handle the complex formulas i use. However it finds the 97 ver (probably because it is the first one it comes across while searching the drive).

                                  Is there a way to find the path to a specific .exe? (ie excel2k.exe as opposed to excel97.exe.

                                  Or perhaps there is a way to find the ver with the newest creation date.

                                  I realize this may be too diffiult in which case I can just rename excel97.exe to excel.exee and it wont get found

                                  ------------------
                                  Kind Regards
                                  Mike

                                  Comment


                                  • #18
                                    I would say a registry search would be the answer, or you could do a brute-force scan of the hard drive(s).

                                    Having more than one copy of Excel installed seems like a waste of good disk real estate to me! How many folks would be likely to have such a set up?

                                    ------------------
                                    Lance
                                    PowerBASIC Support
                                    mailto:[email protected][email protected]</A>
                                    Lance
                                    mailto:[email protected]

                                    Comment


                                    • #19
                                      One more thing...

                                      Lance, thx for the example. I would never have figured out the BYVAL thing or known that the returned:
                                      pointer to buffer for string for executable file
                                      is converted to a string by declaring the name as ASCIIZ!
                                      It's not "converted" as such... we passed the ASCIIZ string buffer BYREF which actually passes a pointer (whose target is the string) to the API. No actual "conversion" took place.

                                      It's similar for the BYCOPY... the API is expecting pointers to string buffers, so by passing it BYCOPY we send the API a pointer to a raw copy of string data. If I uses ASCIIZ strings for all 3 parameters, the BYCOPY would not be required.

                                      You may want to study the manual recarding parameter passing - you'll need to know about it when dealing with calling API functions, and it is especially helpful if you want to convert code from C or VB to PowerBASIC.

                                      ------------------
                                      Lance
                                      PowerBASIC Support
                                      mailto:[email protected][email protected]</A>
                                      Lance
                                      mailto:[email protected]

                                      Comment


                                      • #20
                                        On my site (allways see profile) you find a helpfile wich contains a topic "Check the version of your word processor."
                                        You simply substitute DOC for CSV.
                                        http://pbsoft.bkln.net/vhindex.html




                                        ------------------
                                        hellobasic

                                        Comment

                                        Working...
                                        X