![]() |
How to use macro to dynamically add the VBA code and data together
I am working on a project to generate the the report displayed on web or downloaded as excel by using CGI program. The CGI program is responsible to read the text generated dynamically by submit the SQL query (in CGI) to DB and obtain the result. My problem is the report generated is not the excel file but I need to add the VBA code into the generated report. Can this be done?
In addition, I want to open the file in which the file name is unknown until the CGI program pass the filename, how excel macro can accept the file name from CGI program. Thanks. |
How to use macro to dynamically add the VBA code and data together
To provide more information, here is the vba that I have developed.
Sub TestOpenHyperLink() Dim xOpenedBkName As String Set xWB = ActiveWorkbooks Set xWS = xWB.Worksheets(1) Application.DisplayAlerts = False xWS.Activate Workbooks.OpenText Filename:=Range("A1").Value, origin:=xlWindows, DataType:=xlDelimited, _ tab:=True xOpenedBkName = ActiveWorkbook.Name Workbooks(xOpenedBkName).Activate Sheets(1).Activate Cells.Select Selection.Copy xWB.Activate Sheets.Add after:=Sheets(1) Sheets(2).Select 'xWB.Sheets("Sheet2").Select ActiveSheet.Paste Sheets(2).Name = "Report" Sheets(xWS.Name).Delete Sheets("Report").Activate Range("A1").Select Application.CutCopyMode = False Workbooks(xOpenedBkName).Close Application.CutCopyMode = False Application.DisplayAlerts = True End Sub I fact, how can I pass the filename value from CGI program to replace the Range("A1").value [It contains the URL of the plain text file] within OpenText function in this VBA code. "OpenFile" wrote: I am working on a project to generate the the report displayed on web or downloaded as excel by using CGI program. The CGI program is responsible to read the text generated dynamically by submit the SQL query (in CGI) to DB and obtain the result. My problem is the report generated is not the excel file but I need to add the VBA code into the generated report. Can this be done? In addition, I want to open the file in which the file name is unknown until the CGI program pass the filename, how excel macro can accept the file name from CGI program. Thanks. |
All times are GMT +1. The time now is 01:36 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com