Launch a shell and keep control in Excel
pivecleyrac
Posted messages
8
Status
Member
-
yg_be Posted messages 23437 Registration date Status Contributor Last intervention -
yg_be Posted messages 23437 Registration date Status Contributor Last intervention -
Hello,
I am looking to update an Excel file upon opening it.
I am on a Dolibarr server, where I manage a pricing database for items, and I have an Excel file that retrieves the prices. However, I have not been able to connect to the database, so I created a PHP file on my site that generates a .csv file in my download directory.
When I open my Excel file, I use a shell command to launch the PHP file via Chrome.
The problem is that I lose control of Excel, and therefore cannot continue my macro automatically.
Here is my macro:
If anyone has suggestions, I would be grateful.
Thanks in advance.
Christophe
I am looking to update an Excel file upon opening it.
I am on a Dolibarr server, where I manage a pricing database for items, and I have an Excel file that retrieves the prices. However, I have not been able to connect to the database, so I created a PHP file on my site that generates a .csv file in my download directory.
When I open my Excel file, I use a shell command to launch the PHP file via Chrome.
The problem is that I lose control of Excel, and therefore cannot continue my macro automatically.
Here is my macro:
Sub Lance_Tarif() Dim navigate As String navigate = "https://my site name/excel.php" Shell "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe " & navigate, 0 ..... the macro continues End Sub
If anyone has suggestions, I would be grateful.
Thanks in advance.
Christophe
7 answers
-
yg_be Posted messages 23437 Registration date Status Contributor Last intervention Ambassadeur 1 588
Hello, do you mean that the macro stops while waiting for Chrome to finish? -
Hello and thank you for your interest in my question.
No, the macro continues, unfortunately, but the Chrome window becomes active and the rest.
I say unfortunately because I would like the macro to wait for the end of the file download process before continuing. I set a pause with Application.Wait (Now + TimeValue("0:00:09")), but depending on the speed of the connection, sometimes it's not long enough.
Thank you in advance. -
Yes, indeed, the file I'm creating allows for data retrieval.
It is necessarily absent before being created; I delete it at the end of my macro.
To check for presence, do we use a do while? -
Thank you for the information. I did:
While Fs.FileExists("monfichier.txt") <> True Application.Wait (Now + TimeValue("0:00:01")) Wend
It seems to be working.
As I explained in my first message, my macro opens Chrome to download the file. I would like to do this in the background and keep control of Excel. For the Shell definition, I used this page https://docs.microsoft.com/fr-fr/office/vba/language/reference/user-interface-help/shell-function
but putting 0 or 6 does not change anything...
Dim navigate As String navigate = "https://le nom de mon site/excel.php" Shell "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe " & navigate, 0
-
-
Hello,
could you open the application in minimized mode?
ex: start /min "" "C:\Windows\notepad.exe"
Best regards, -
Hello Chris_33000
Thank you for your response.
I can't find how to write the start function. Could you tell me where it can be found, thanks in advance.
Best regards.-
-
-
-
-
It's almost perfect gentlemen, just one more question, the command
Shell "C:\Program Files\Internet Explorer\iexplore.exe " & navigate , vbMinimizedNoFocus
opens a window asking me whether I want to open or save the file. Is it possible to force the file to save? Perhaps in PHP?
Thank you in advance.
-