Microsoft Excel Data Connections - Alter Command Text

to_mas_re

New Member
Hi everyone,

I'm trying to change Command Text box in Connection Properties (see picture). It is an existing data connection in Excel and I need to change the query.

1611300115365.png

I already found this thread discussing altering Connection String but I was not able to alter the code for my purposes. What I tried is this:
Code:
Dim wb As Object

wb = GetWorkbook(handle, workbookname)

Dim oledbCn As OLEDBCommand

oledbCn = wb.Connections(connectionname).OLEDBConnection
query = oledbCn.CommandText

Also I added system.data.oledb into object's name space but it seems "CommandText" is not part of OLEDBConnection, although it is property of OLEDBConnection here.

I don't know what to do now.
 
Top