Save php parameter in vba variable

Asked

Viewed 42 times

0

I have a form I step a parameter and at the same time open an Excel spreadsheet. Following example:

<?php
if (isset($_GET["param"]) && !empty($_GET["param"])) {
    $param =  $_GET["param"]; 
    exec("START teste.xlsx $param");   
}else{  
    echo "Não foi enviado parâmetro.";
}
?>

<form method="GET" action="#">
    <input type="text" id="param" name="param">
    <button type="submit"> ABRIR EXCEL </button>
</form>

How do I save this parameter in a variable in the Excel vba to be able to use it ?

1 answer

1


Good afternoon. You can use the method described in this article http://www.excelflex.com.br/avancado-ler-o-parametro-da-linha-de-comando-pelo-vba/

Complementing the answer:

#If Win64 Then
Private Declare PtrSafe Function GetCommandLineL Lib "kernel32" _
    Alias "GetCommandLineA" () As LongPtr
Private Declare PtrSafe Function lstrcpyL Lib "kernel32" _
    Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As LongPtr) As Long
Private Declare PtrSafe Function lstrlenL Lib "kernel32" _
    Alias "lstrlenA" (ByVal lpString As LongPtr) As Long
#Else
Private Declare Function GetCommandLineL Lib "kernel32" _
    Alias "GetCommandLineA" () As Long
Private Declare Function lstrcpyL Lib "kernel32" _
    Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Long) As Long
Private Declare Function lstrlenL Lib "kernel32" _
    Alias "lstrlenA" (ByVal lpString As Long) As Long
#End If

Function GetCommandLine() As String
  Dim strReturn As String
  #If Win64 Then
  Dim lngPtr As LongPtr
  #Else
  Dim lngPtr As Long
  #End If
  Dim StringLength As Long
  'Get the pointer to the commandline string
  lngPtr = GetCommandLineL
  'get the length of the string (not including the terminating null character):
  StringLength = lstrlenL(lngPtr)
  'initialize our string so it has enough characters including the null character:
  strReturn = String$(StringLength + 1, 0)
  'copy the string we have a pointer to into our new string:
  lstrcpyL strReturn, lngPtr
  'now strip off the null character at the end:
  GetCommandLine = Left$(strReturn, StringLength)
End Function
  • While this link may answer the question, it is best to include the essential parts of the answer here and provide the link for reference. Replies per link only can be invalidated if the page with the link is changed. - Of Revision

  • 1

    @Thanks for the tip. I included the content in the reply.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.