While there is no way that I know of to hide the query information, you can create a set of protected procedures that:
- adds the authentication (connection string)
- runs the query
- then removes it again.
- First you'll want to create a new VBA module in your Excel worksheet with procedures that look something like this:
Sub AddConnect()
'this will add the connection string to
'all connections in the active workbook
For Each CN In ActiveWorkbook.Connections
CN.ODBCConnection.BackgroundQuery = False 'this line is optional
CN.ODBCConnection.Connection = _
"ODBC;DRIVER={Progress OpenEdge 10.1C Driver};" & _
"UID=YOURUSERNAME;PWD=YOURPASSWORD;" & _
"HOST=YOURHOST;PORT=YOURPORT;DB=YOURDATABASE;" & _
"DefaultIsolationLevel=READUNCOMMITTED"
Next
End Sub
Sub RemoveConnect()
'this will remove the connection string from
'all connections in the active workbook
For Each CN In ActiveWorkbook.Connections
CN.ODBCConnection.Connection = "ODBC;"
Next
End Sub
Sub ListConnections()
'this will list all query connection strings
'in the active workbook
For Each CN In ActiveWorkbook.Connections
MsgBox (CN.ODBCConnection.Connection)
Next
End Sub
Sub RefreshAll()
'this will refresh all the data connections in the active workbook
AddConnect 'add the connection strings
ActiveWorkbook.RefreshAll 'refresh all connections
RemoveConnect 'remove the connection strings
End Sub - You can then password protect the module by right-clicking it and selecting properties.
- Then check "Lock project for viewing" and enter your password. Finally, click OK.
- You can then add a command button to your worksheet with the macro assigned to RefreshAll().
can you please suggest how to apply it for olap connection
ReplyDeleteSame as above. How to do it for an OLAP connection. Please. Thanks.
ReplyDelete