Re: Trying to write Excel automation code in VFP9SP2 from Excel 2013 VBA macro code
Ok - I could not remember the exact thing - when I was just looking for it - so I called my buddy. Go to Trust Center - Trust Center Settings... - File Block Settings - then Check to Open for Excel 2-4 Worksheets and Workbooks, also Excel 2-4 Macrosheets! That should do it!!! On 9/23/2016 4:37 PM, Kurt at VR-FX wrote: You're security crap sounds VERY Familiar! Like something we had a problem with and a QA buddy of mine found the resolution when he was testing something else. Let me get back to you shortly with hopefully an answer! -K- On 9/23/2016 4:14 PM, mbsoftwaresoluti...@mbsoftwaresolutions.com wrote: On 2016-09-21 10:38, Kurt Wendt wrote: Mike - Here you go. Here's some of the code in our system: tab2_macro = ssMacroName+"!Module3.Tab2" oExcel.WINDOWS(JUSTFNAME(ssName)).ACTIVATE oExcel.Sheets("Account Level").SELECT oExcel.RANGE("A2").SELECT After the above code runs - then this is the call to the Macro: oExcel.APPLICATION.RUN(tab2_macro) When I ran my adaptation, I got an error about Security settings, despite my Excel setting being to Allow macros to be run (least secure). Do you still do this today or is this logic dated perhaps to a time prior to M$ locking everything down? I also got out my famous Microsoft Office Automation With Visual FoxPro book by Tamar and Della (edited by our very own Ted Roche) and was trying to use the example on pages 206-207 whereby I created the macro code into a text file and then added it in and ran it, but with the same error about security as well. :-( I basically ended up running loops to create the following commands which I stuffed into Call_It and then let it used my routine which worked fine. But this isn't the automation I was hoping to achieve. I'm sure it can be done; I'm just still searching for the way around the "security" error roadblocks. Sub Call_it() Application.DisplayAlerts = False Excel.Workbooks.Add Call Create_OP_File("210001", "v_op_210001_1", "1", False) Call Create_OP_File("210001", "v_op_210001_2", "2", False) Call Create_OP_File("210001", "v_op_210001_3", "3", True) ActiveWorkbook.Close Excel.Workbooks.Add Call Create_OP_File("210002", "v_op_210002_1", "1", False) Call Create_OP_File("210002", "v_op_210002_2", "2", False) Call Create_OP_File("210002", "v_op_210002_3", "3", True) ActiveWorkbook.Close ' ...and this goes on for 53 more different provider numbers, each with 3 file type calls like the examples above End Sub Sub Create_OP_File(ByVal tcProvNum As String, ByVal tcView As String, _ ByVal tcRecType As String, _ ByVal EOFFLag As Boolean) ' load the outpatient record types for given provider Dim lcSQL As String Dim lcFilename As String lcSQL = "SELECT * FROM " + tcView With ActiveSheet.ListObjects.Add(SourceType:=0, Source:="ODBC;DATABASE=mydatabase;DESCRIPTION=MyData;DSN=My_DSH;OPTION=69533696;PORT=3306;SERVER=10.8.20.109;UID=userid;", Destination:=Range("$A$1")).QueryTable .CommandType = 2 .CommandText = Array(lcSQL) .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .PreserveColumnInfo = True .SourceConnectionFile = "G:\Mike\outpatient.odc" .Refresh BackgroundQuery:=False End With ActiveSheet.Name = "Record Type " + tcRecType If Not EOFFLag Then Sheets.Add After:=ActiveSheet Else lcFilename = "c:\crap\" + tcProvNum + "_op.xlsx" ActiveWorkbook.SaveAs Filename:=lcFilename, FileFormat:=xlOpenXMLWorkbook, Password:="mypwd", CreateBackup:=False End If End Sub [excessive quoting removed by server] ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/57e59898.5080...@optonline.net ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Re: Trying to write Excel automation code in VFP9SP2 from Excel 2013 VBA macro code
You're security crap sounds VERY Familiar! Like something we had a problem with and a QA buddy of mine found the resolution when he was testing something else. Let me get back to you shortly with hopefully an answer! -K- On 9/23/2016 4:14 PM, mbsoftwaresoluti...@mbsoftwaresolutions.com wrote: On 2016-09-21 10:38, Kurt Wendt wrote: Mike - Here you go. Here's some of the code in our system: tab2_macro = ssMacroName+"!Module3.Tab2" oExcel.WINDOWS(JUSTFNAME(ssName)).ACTIVATE oExcel.Sheets("Account Level").SELECT oExcel.RANGE("A2").SELECT After the above code runs - then this is the call to the Macro: oExcel.APPLICATION.RUN(tab2_macro) When I ran my adaptation, I got an error about Security settings, despite my Excel setting being to Allow macros to be run (least secure). Do you still do this today or is this logic dated perhaps to a time prior to M$ locking everything down? I also got out my famous Microsoft Office Automation With Visual FoxPro book by Tamar and Della (edited by our very own Ted Roche) and was trying to use the example on pages 206-207 whereby I created the macro code into a text file and then added it in and ran it, but with the same error about security as well. :-( I basically ended up running loops to create the following commands which I stuffed into Call_It and then let it used my routine which worked fine. But this isn't the automation I was hoping to achieve. I'm sure it can be done; I'm just still searching for the way around the "security" error roadblocks. Sub Call_it() Application.DisplayAlerts = False Excel.Workbooks.Add Call Create_OP_File("210001", "v_op_210001_1", "1", False) Call Create_OP_File("210001", "v_op_210001_2", "2", False) Call Create_OP_File("210001", "v_op_210001_3", "3", True) ActiveWorkbook.Close Excel.Workbooks.Add Call Create_OP_File("210002", "v_op_210002_1", "1", False) Call Create_OP_File("210002", "v_op_210002_2", "2", False) Call Create_OP_File("210002", "v_op_210002_3", "3", True) ActiveWorkbook.Close ' ...and this goes on for 53 more different provider numbers, each with 3 file type calls like the examples above End Sub Sub Create_OP_File(ByVal tcProvNum As String, ByVal tcView As String, _ ByVal tcRecType As String, _ ByVal EOFFLag As Boolean) ' load the outpatient record types for given provider Dim lcSQL As String Dim lcFilename As String lcSQL = "SELECT * FROM " + tcView With ActiveSheet.ListObjects.Add(SourceType:=0, Source:="ODBC;DATABASE=mydatabase;DESCRIPTION=MyData;DSN=My_DSH;OPTION=69533696;PORT=3306;SERVER=10.8.20.109;UID=userid;", Destination:=Range("$A$1")).QueryTable .CommandType = 2 .CommandText = Array(lcSQL) .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .PreserveColumnInfo = True .SourceConnectionFile = "G:\Mike\outpatient.odc" .Refresh BackgroundQuery:=False End With ActiveSheet.Name = "Record Type " + tcRecType If Not EOFFLag Then Sheets.Add After:=ActiveSheet Else lcFilename = "c:\crap\" + tcProvNum + "_op.xlsx" ActiveWorkbook.SaveAs Filename:=lcFilename, FileFormat:=xlOpenXMLWorkbook, Password:="mypwd", CreateBackup:=False End If End Sub [excessive quoting removed by server] ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/57e592a1.60...@optonline.net ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
RE: Trying to write Excel automation code in VFP9SP2 from Excel 2013 VBA macro code
On 2016-09-21 10:38, Kurt Wendt wrote: Mike - Here you go. Here's some of the code in our system: tab2_macro = ssMacroName+"!Module3.Tab2" oExcel.WINDOWS(JUSTFNAME(ssName)).ACTIVATE oExcel.Sheets("Account Level").SELECT oExcel.RANGE("A2").SELECT After the above code runs - then this is the call to the Macro: oExcel.APPLICATION.RUN(tab2_macro) When I ran my adaptation, I got an error about Security settings, despite my Excel setting being to Allow macros to be run (least secure). Do you still do this today or is this logic dated perhaps to a time prior to M$ locking everything down? I also got out my famous Microsoft Office Automation With Visual FoxPro book by Tamar and Della (edited by our very own Ted Roche) and was trying to use the example on pages 206-207 whereby I created the macro code into a text file and then added it in and ran it, but with the same error about security as well. :-( I basically ended up running loops to create the following commands which I stuffed into Call_It and then let it used my routine which worked fine. But this isn't the automation I was hoping to achieve. I'm sure it can be done; I'm just still searching for the way around the "security" error roadblocks. Sub Call_it() Application.DisplayAlerts = False Excel.Workbooks.Add Call Create_OP_File("210001", "v_op_210001_1", "1", False) Call Create_OP_File("210001", "v_op_210001_2", "2", False) Call Create_OP_File("210001", "v_op_210001_3", "3", True) ActiveWorkbook.Close Excel.Workbooks.Add Call Create_OP_File("210002", "v_op_210002_1", "1", False) Call Create_OP_File("210002", "v_op_210002_2", "2", False) Call Create_OP_File("210002", "v_op_210002_3", "3", True) ActiveWorkbook.Close ' ...and this goes on for 53 more different provider numbers, each with 3 file type calls like the examples above End Sub Sub Create_OP_File(ByVal tcProvNum As String, ByVal tcView As String, _ ByVal tcRecType As String, _ ByVal EOFFLag As Boolean) ' load the outpatient record types for given provider Dim lcSQL As String Dim lcFilename As String lcSQL = "SELECT * FROM " + tcView With ActiveSheet.ListObjects.Add(SourceType:=0, Source:="ODBC;DATABASE=mydatabase;DESCRIPTION=MyData;DSN=My_DSH;OPTION=69533696;PORT=3306;SERVER=10.8.20.109;UID=userid;", Destination:=Range("$A$1")).QueryTable .CommandType = 2 .CommandText = Array(lcSQL) .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .PreserveColumnInfo = True .SourceConnectionFile = "G:\Mike\outpatient.odc" .Refresh BackgroundQuery:=False End With ActiveSheet.Name = "Record Type " + tcRecType If Not EOFFLag Then Sheets.Add After:=ActiveSheet Else lcFilename = "c:\crap\" + tcProvNum + "_op.xlsx" ActiveWorkbook.SaveAs Filename:=lcFilename, FileFormat:=xlOpenXMLWorkbook, Password:="mypwd", CreateBackup:=False End If End Sub ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/bbc2641ef4c053bfc1c5e17183f13...@mbsoftwaresolutions.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
RE: Trying to write Excel automation code in VFP9SP2 from Excel 2013 VBA macro code
Mike - Here you go. Here's some of the code in our system: tab2_macro = ssMacroName+"!Module3.Tab2" oExcel.WINDOWS(JUSTFNAME(ssName)).ACTIVATE oExcel.Sheets("Account Level").SELECT oExcel.RANGE("A2").SELECT After the above code runs - then this is the call to the Macro: oExcel.APPLICATION.RUN(tab2_macro) As you can - its loading data into the 2nd Tab of the spreadsheet. Hopefully this can help get you started! Regards, Kurt Wendt Senior Systems Analyst Tel. +1-212-747-9100 www.GlobeTax.com -Original Message- From: ProfoxTech [mailto:profoxtech-boun...@leafe.com] On Behalf Of mbsoftwaresoluti...@mbsoftwaresolutions.com Sent: Wednesday, September 21, 2016 10:00 AM To: profoxt...@leafe.com Subject: RE: Trying to write Excel automation code in VFP9SP2 from Excel 2013 VBA macro code On 2016-09-21 09:33, Kurt Wendt wrote: > I agree - that's what you should do. At my job here - there is a > "Report" that's done the same way. Although strangely - the way they > had it setup before I started on the system - is one spreadsheet that > is the Template for the report. Then, another spreadsheet has the > Macros that get called. Also, FYI - for this report - its 3 Tabs of > data. A Stored Proc is called - that generates multiple sets of data - > and then that data is used to populate the tabs in the Excel file. > Somewhat similar to what you need to do... > Sounds exactly what I'm trying to do. So from VFP, open the Excel file (all via automation of course), then call the embedded macro with parms, right? How do you call a Macro via automation? I'll have to research it. [excessive quoting removed by server] ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/80838f1ca795b14ea1af48659f35166f2eb...@drexch02.corp.globetax.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
RE: Trying to write Excel automation code in VFP9SP2 from Excel 2013 VBA macro code
On 2016-09-21 09:33, Kurt Wendt wrote: I agree - that's what you should do. At my job here - there is a "Report" that's done the same way. Although strangely - the way they had it setup before I started on the system - is one spreadsheet that is the Template for the report. Then, another spreadsheet has the Macros that get called. Also, FYI - for this report - its 3 Tabs of data. A Stored Proc is called - that generates multiple sets of data - and then that data is used to populate the tabs in the Excel file. Somewhat similar to what you need to do... Sounds exactly what I'm trying to do. So from VFP, open the Excel file (all via automation of course), then call the embedded macro with parms, right? How do you call a Macro via automation? I'll have to research it. ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/1960e8470b83283c99418f41ed2c0...@mbsoftwaresolutions.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
RE: Trying to write Excel automation code in VFP9SP2 from Excel 2013 VBA macro code
I agree - that's what you should do. At my job here - there is a "Report" that's done the same way. Although strangely - the way they had it setup before I started on the system - is one spreadsheet that is the Template for the report. Then, another spreadsheet has the Macros that get called. Also, FYI - for this report - its 3 Tabs of data. A Stored Proc is called - that generates multiple sets of data - and then that data is used to populate the tabs in the Excel file. Somewhat similar to what you need to do... Regards, Kurt Wendt Senior Systems Analyst Tel. +1-212-747-9100 www.GlobeTax.com -Original Message- From: ProfoxTech [mailto:profoxtech-boun...@leafe.com] On Behalf Of mbsoftwaresoluti...@mbsoftwaresolutions.com Sent: Wednesday, September 21, 2016 9:28 AM To: profoxt...@leafe.com Subject: Re: Trying to write Excel automation code in VFP9SP2 from Excel 2013 VBA macro code On 2016-09-20 03:56, Alan Bourke wrote: > Well in terms of the named parameters don't you just need to use > positional parameters in the Add() instead? > > loListObject = loSheet.ListObjects.Add(0, "ODBC:" ... ) Or maybe I can create a template file with the macro embedded, and call the macro, passing the parameters it needs so it can keep it's VBA style? [excessive quoting removed by server] ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/80838f1ca795b14ea1af48659f35166f2eb...@drexch02.corp.globetax.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Re: Trying to write Excel automation code in VFP9SP2 from Excel 2013 VBA macro code
On 2016-09-20 03:56, Alan Bourke wrote: Well in terms of the named parameters don't you just need to use positional parameters in the Add() instead? loListObject = loSheet.ListObjects.Add(0, "ODBC:" ... ) Or maybe I can create a template file with the macro embedded, and call the macro, passing the parameters it needs so it can keep it's VBA style? ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/590cf0e20bcada554f0a5474aea0b...@mbsoftwaresolutions.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Re: Trying to write Excel automation code in VFP9SP2 from Excel 2013 VBA macro code
Well in terms of the named parameters don't you just need to use positional parameters in the Add() instead? loListObject = loSheet.ListObjects.Add(0, "ODBC:" ... ) -- Alan Bourke alanpbourke (at) fastmail (dot) fm ___ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/1474358193.221249.731094553.797b2...@webmail.messagingengine.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.