database - How to link Connection to Refresh Table in VBA -
i need refresh number of connections in excel, without storing password in connection details. using vba script attempt this. code is:
sub test() dim con adodb.connection dim rs adodb.recordset set con = new adodb.connection set rs = new adodb.recordset ' connection string information db variable (strcon) strcon = "driver={dummy}; " & _ "connectstring=(description=" & _ "(address=(protocol=dummy)" & _ "(host=dummy)(port=dummy))" & _ "(connect_data=(service_name = dummy))); uid=dummy; pwd=dummy;" ' opens above connection string. con.open (strcon) activeworkbook.refreshall activeworkbook.save end sub
my code seems open connection, , refreshes tables. however, still asking me input password. how use open connection refresh tables?
i had delete connections in database , use vba code replicate connections in series of sql queries. basis of code using is:
'declare variables' set objmyconn = new adodb.connection set objmyrecordset = new adodb.recordset dim strsql string 'open connection' objmyconn.connectionstring = "driver={microsoft odbc oracle}; " & _ "connectstring=(description=" & _ "(address=(protocol=***)" & _ "(host=*****)(port=****))" & _ "(connect_data=(service_name = ****))); uid=****; pwd=*****;" objmyconn.open 'set , excecute sql command' strsql = "select distinct * temp_final_complaints_report" 'open recordset' set objmyrecordset.activeconnection = objmyconn objmyrecordset.open strsql 'copy data excel' sheets("complaints report").range("a2").copyfromrecordset (objmyrecordset)
i can encrypt module saved password.
Comments
Post a Comment