Suppress the message "Getting Data..." when importing from ODBC..? - excel

In Excel 2007, when importing data via SQL/ODBC, it displays the message "Getting data" in the top-left cell of the import range. This occurs whether the query is run from the GUI or from VBA.
Can this message be suppressed..??? There seem to be no settings for it, either in the GUI or the VBA object properties of the WorkbookConnection, ODBCConnection, ListObject, or QueryTable.
I would like to create a customized "please wait" message with an animation, but the "Getting Data" message creates a visual conflict.
I tried the following, but it didn't suppress the message:
xl.ScreenUpdating = False
xl.DisplayAlerts = False
ExternalData_1: Getting Data...

Try disabling BackgroundQuery parameter:
With Selection.QueryTable
.BackgroundQuery = False
End With

Related

Excel Interop - Display full screen error?

I'm using Excel Introp for a .net application to embed an Excel workbook in a windows userform.
excApp.Visible = False
wb = excApp.Workbooks.Open(directOpenPath) ' , [ReadOnly]:=False, IgnoreReadOnlyRecommended:=True)
wb.Saved = True ' necessary to prevent Excel has stopped working error and to not actually do a save
hwnd1 = CType(excApp.Hwnd, IntPtr)
SetParent(excApp.Hwnd, pnlExcel.Handle)
SendMessage(excApp.Hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
MoveWindow(hwnd1, 0, 0, pnlExcel.Width, pnlExcel.Height, True)
excApp.Visible = True
There are ActiveX buttons on the worksheet that work fine when I open using the above code.
However, it is my desire to make the object look less like Excel so I wanted to hide the ribbon, formula bar, etc.
I added the line: excApp.DisplayFullScreen=True. Upon doing that, clicking on a button no longer kicked off the associated macro. Additionally, I could no longer click on any cell in the worksheet. This seems like odd behavior but I have traced it down to the DisplayFullScreen line.
Also I am trying to include the following:
excApp.ActiveWindow.DisplayWorkbookTabs = False
excApp.ActiveWindow.DisplayHeadings = False
excApp.ActiveWindow.DisplayGridlines = False
But I get a object not set to reference error. If I add excApp.ActiveWindow.Activate, the worksheet "locks up" again and I can't click on any cells.
Any ideas?

How to access SAP using Excel VBA?

I am trying to log on to SAP. The Excel VBA code gives me a popup window confirming my information however when I submit the form it does not take me to a new SAP window.
Additionally is there a way to automate all the popup boxes asking for confirmation on my information? I want this code eventually to run at certain times of the day, and I might not be available to input any data.
Sub login1()
Dim sap As Object
Dim conn As Object
Set sap = CreateObject("SAP.Functions")
Set conn = sap.Connection
conn.System = "System Test Environment"
conn.client = "100"
conn.user = "user"
conn.Password = "password"
conn.Language = "EN"
If conn.logon(0, False) <> True Then
MsgBox "Logon to the SAP system is not possible", vbOKOnly, "Comment"
Else
End If
End Sub
This Macro will never open a SAP Window - it will create an SAP-Object within VBA where you can work with SAP-RFC-Functions. (Reading Data from SAP, Writing Data into SAP)
In your version the SAP connection will be unaccessible after "End Sub". You have to declair the Object outside the sub.
This works silent (without dialog) for me:
Dim sap As Object
Public Function login1() As Boolean
Set sap = CreateObject("SAP.Functions")
sap.Connection.System = "System Test Environment"
sap.Connection.client = "100"
sap.Connection.user = "user"
sap.Connection.Password = "password"
sap.Connection.Language = "EN"
If sap.Connection.logon(0, False) <> True Then
sap.RemoveAll
MsgBox "Logon to the SAP system is not possible", vbOKOnly, "Comment"
Else
login1 = true
End If
End Function
Public Function SAPLogoff()
On Error Resume Next
sap.RemoveAll
sap.Connection.logoff
LoggedOn = False
Set sap = Nothing
'Set conn = Nothing
End Function
Since you want to "open a new SAP Window" you have to make a different approach!
At First try to open the new instance of SAP from the DOS Commandline with "sapshcut":
C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapshcut.exe -system="System Test Environment" -client="100" -user="user" -password="password" -language="EN"
If your SystemName has no Spaces (and I belive so!) then you can write it also like:
C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapshcut.exe -system=SystemTestEnvironment -client=100 -user=user -password=password -language=EN
When this call works with your credentials, then you can transfer it to Excel like this:
Sub login1()
Call Shell("C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapshcut.exe -system=SystemTestEnvironment -client=100 -user=user -password=password -language=EN",vbNormalFocus)
End Sub
You could also add a transaction by adding "-command=your_tcode" to the String.
If your have spaces in the parameters and you could only start it with -system="System Test Environment" from the Commanline, you will have to escape this in Excel with -system="""System Test Environment""" (!)

Check if an Add-in is installed and running VBA

I am trying to check if an add-in is installed and running. I am using this piece of code:
On Error Resume Next:
Set SolverNome1 = AddIns("Solver Add-In") 'Solver may have two different names
Set SolverNome2 = AddIns("Solver")
MsgBox IsEmpty(SolverNome1)
MsgBox IsEmpty(SolverNome2)
If IsEmpty(SolverNome1) And IsEmpty(SolverNome2) Then
MsgBox "Install Solver add-in before trying to install this add-in.", vbExclamation
Application.myAddInName.Installed = False 'uninstall my add-in
End If
The problem is that even with the Solver Uninstalled I still get IsEmpty(SolverNome1) = false so my condition clause doesn't work as desired. I guess there I am misunderstanding the concept of installed or not. What piece of code should I be using to check if solver is running?
Answering my on question:
It is necessary to access the .installed property like this:
myBoolean1 = SolverNome1.Installed 'will return false because the add-in is set and not installed
myBoolean2 = SolverNome1.Installed 'won't return because add-in is not set

Forms with vba code and importing

How to create an access form which has two fields for importing two different excel files, and after selecting excel files press the button to run a query (already exist) and automatically export the query result in excel sheet. I was able to create the vba code (once played the import dialog will pop up waiting the user to enter the file path then pops up another time for the second file, another dialoge for exporting the result to excel. but the problem is how to do it using Forms in Microsoft Access.please give me suggestions or reference.
Agree with Boeckm, your question is a little lacking in detail :-)
If you are asking for the VBA code to fire the macro's you already have then simply create a button and add the following to the [on click] property
Private Sub Excel_button_Click(Cancel As Integer)
DoCmd.SetWarnings False ' Switch off "Are you sure" message
Dim stDocName As String
stDocName = "qry_Import file 1"
DoCmd.OpenQuery stDocName, acNormal, acEdit
stDocName = "qry_Import file 2"
DoCmd.OpenQuery stDocName, acNormal, acEdit
stDocName = "qry_Export file 3"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings True ' Switch on "Are you sure" message
End Sub
You can also build this in a single button using the wizzard (select misc, run query and select the first import query. Go back to the button and edit the [embedded macro] adding the others. You can also add the set warning = off to the series if required).

ADODB.Connection undefined

Reference Excel VBA to SQL Server without SSIS
After I got the above working, I copied all the global variables/constants from the routine, which included
Const CS As String = "Driver={SQL Server};" _
& "Server=****;" _
& "Database=****;" _
& "UID=****;" _
& "PWD=****"
Dim DB_Conn As ADODB.Connection
Dim Command As ADODB.Command
Dim DB_Status As Stringinto a similar module in another spreadsheet. I also copied into the same module
Sub Connect_To_Lockbox()
If DB_Status <> "Open" Then
Set DB_Conn = New Connection
DB_Conn.ConnectionString = CS
DB_Conn.Open ' problem!
DB_Status = "Open"
End If
End SubI added the same reference (ADO 2.8)
The first spreadsheet still works; the seccond at DB_Conn.Open pops up "Run-time error '-214767259 (80004005)': [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
Removing the references on both, saving files, re-opening, re-adding the references doesn't help. The one still works and the other gets the error.
?!?
I observed the same error message and in my case nothing had changed. I wondered if my odbc driver needed to be reinstalled (based on what i read online). In any case, restarting excel did the trick. Sometimes the solution is much simpler. :-)
When the error pops up, check your "locals" windows to see what the CS holds. View > Locals Window
Problem: Your constant isn't found by the compiler.
Solution: With the constant being located in a separate module, you'll need to set it as Public for the other code to see it.
Proof:
In order to prove this theory you can do the following:
Open a new Excel spreadsheet
Go to the VBA designer and add a new module
In this module put:
Const TestString As String = "Test String"
Then add the following code to ThisWorkbook:
Public Sub TestString()
MsgBox (TestString)
End Sub
After adding this return to the workbook and add a button, selecting "TestString" as the macro to run when clicked.
Click the button and a blank message box will appear.
Go back to the VBA designer and change the const in Module1 to Public
Click the button on the spreadsheet and you should now see "Test String" in the message box.
I realize that this question is really old. But for the record I want to document my solutions for the error here: It was a data related error in a spreadsheet! A column was formatted as date and contained a value 3000000. Changing the Format to numbers solved the Error 80004005.

Resources