Help
  • Explore Community
  • Get Started
  • Ask the Community
  • How-To & Best Practices
  • Contact Support
Notifications
Login / Register
Community
Community
Notifications
close
  • Forums
  • Knowledge Center
  • Events & Webinars
  • Ideas
  • Blogs
Help
Help
  • Explore Community
  • Get Started
  • Ask the Community
  • How-To & Best Practices
  • Contact Support
Login / Register
Sustainability
Sustainability

We Value Your Feedback!
Could you please spare a few minutes to share your thoughts on Cloud Connected vs On-Premise Services. Your feedback can help us shape the future of services.
Learn more about the survey or Click here to Launch the survey
Schneider Electric Services Innovation Team!

[Imported] [Solved] Importing data into a Data Table from an Excel file

EcoStruxure Geo SCADA Expert Forum

Schneider Electric support forum about installation, configuration, integration and troubleshooting of EcoStruxure Geo SCADA Expert (ClearSCADA, ViewX, WebX).

cancel
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Home
  • Schneider Electric Community
  • Remote Operations
  • EcoStruxure Geo SCADA Expert Forum
  • [Imported] [Solved] Importing data into a Data Table from an Excel file
Options
  • Mark Topic as New
  • Mark Topic as Read
  • Float this Topic for Current User
  • Bookmark
  • Subscribe
  • Mute
  • Printer Friendly Page
Invite a Co-worker
Send a co-worker an invite to the portal.Just enter their email address and we'll connect them to register. After joining, they will belong to the same company.
You have entered an invalid email address. Please re-enter the email address.
This co-worker has already been invited to the Exchange portal. Please invite another co-worker.
Please enter email address
Send Invite Cancel
Invitation Sent
Your invitation was sent.Thanks for sharing Exchange with your co-worker.
Send New Invite Close
Top Experts
User Count
sbeadle
Kirk sbeadle Kirk
308
AndrewScott
Admiral AndrewScott
98
BevanWeiss
Spock BevanWeiss
91
AdamWoodlandToo
Lt. Commander AdamWoodlandToo
37
View All
Related Products
product field
Schneider Electric
EcoStruxure™ Geo SCADA Expert

Invite a Colleague

Found this content useful? Share it with a Colleague!

Invite a Colleague Invite
Back to EcoStruxure Geo SCADA Expert Forum
sbeadle
Kirk sbeadle Kirk
Kirk

Posted: ‎2019-10-26 02:42 AM . Last Modified: ‎2023-05-03 12:38 AM

0 Likes
0
1979
  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Permalink
  • Print
  • Email to a Friend
  • Report Inappropriate Content

Link copied. Please paste this link to share this article on your social media post.

Posted: ‎2019-10-26 02:42 AM . Last Modified: ‎2023-05-03 12:38 AM

[Imported] [Solved] Importing data into a Data Table from an Excel file

>>Message imported from previous forum - Category:Scripts and Tips<<
User: mchartrand, originally posted: 2018-10-19 18:03:08 Id:153
This is a re-posting from the obsoleted (October 2018) "Schneider Electric Telemetry & SCADA" forum.

-------------------------------

**_hardin4019:
[Solved] See code below for working version. Note its a good bit longer than some of the other posts and includes enough comments so people can figure it out and use it again.
I need a little help understand what I'm doing wrong.
Client wants to import a list of names, addresses, phone numbers, etc from an excel file stored in a mapped network drive or locally on the server. They want that list to appear on a mimic in CS.
I have seen examples of using ST to fill in a Data Table, but I'm not having any luck with getting that ST linked to my Excel file and the correct fields in the Excel. The Excel file for now has 3 columns: Name, Address, Phone. My Data Table has the same 3 columns. The updating of the Data table doesn't need to be automated, but would be nice if at least once a day it updated on its own. From there, I am assuming a simple Query of that Data Table can display the info in a list on a mimic._**

_Sub InsertData()
Dim EmptyDB, iRowNo As Integer
Dim Name, PhoneNumber, Address As String
'All of the data being inserted is in Sheet1
With Sheets("Sheet1")
Set ado = CreateObject("ADODB.Connection")
Set adoRS = CreateObject("ADODB.Recordset")
EmptyDB = 1
'Skip the header row with header info
iRowNo = 2
'Put in the DSN name, Username, Password below
ado.Open "DSN=ClearSCADA", "username", "password"
'Show message box if connected to DB.
'If ado.State = 1 Then
' MsgBox "Connected"
'End If
'Delete all of the data in the table if the EmptyDB equals 1
If EmptyDB = 1 Then
ado.Execute "DELETE FROM PhoneList"
End If
'Loop until empty row
Do Until .Cells(iRowNo, 1) = "" And .Cells(iRowNo, 2) = "" And .Cells(iRowNo, 3) = ""
sName = .Cells(iRowNo, 1)
sPhoneNumber = .Cells(iRowNo, 2)
sAddress = .Cells(iRowNo, 3)
'Build the query
queryText = "INSERT INTO PhoneList (Name, PhoneNumber, Address) VALUES ('" & sName & "', '" & sPhoneNumber & "', '" & sAddress & "')"
'Execute the query
ado.Execute queryText
'Increment iRowNo and repeat until empty row
iRowNo = iRowNo + 1
Loop
'Close DB connection and message done
ado.Close
Set ado = Nothing
MsgBox "Done"
End With
End Sub_

-------------------------------

bevanweiss:
This *might* be possible using a linked table...
There is an ODBC driver for Excel workbooks.

Failing that, you could create a Data Grid that allows easy copy/paste from Excel directly into it. Then display the Data Grid on the mimic (via an embedded query).

I'll check on the linked table idea when I get into the office..

_________

AWoodland:
I don't believe Excel will work, the Windows permissions will probably block ClearSCADA creating the ODBC connection as its a file rather than a service like MSSQL.

One way could be some simple VB running as a user under Windows Task Scheduler, bit of VBS to read Excel via COM and push it into ClearSCADA via ODBC or COM

__________________

du5tin:
We managed to do this in Excel using the ADODB object to create an ODBC connection to ClearSCADA. The VBA code followed this general form:

_Sub InsertData
Set ado = CreateObject("ADODB.Connection")
Set adoRS = CreateObject("ADODB.Recordset")
ado.Open "DSN=ClearSCADA", username, password
For i = 1 To rowcount
queryText = Build your insert query with data from spreadsheet rows here
ado.Execute queryText
Next
MsgBox "Done"
End Sub_

Notes:

-Your DSN using the ClearSCADA must be configured in the 32-bit ODBC Control Panel. User or System tab likely won't matter, we used the system tab so the DSN was available to multiple users.

- We had to write another bit of logic to delete everything from the datatable for future bulk loads. This script had no logic for modifying existing data. Essentially the query text was "DELETE FROM _DataTableName_".

____________________________________________

du5tin:
On reading the post again I realize that manually loading the data into ClearSCADA via Excel was not Shawn's original intent.

Bevan and Adam have good suggestions if you want to reference some network file somewhere as a bit of a 'live' data source instead.

You might be just as quick to build an interface to manage this data inside ClearSCADA without an external file. There are lots of ways an external file could break: If the client changes the file format (renames or adds a column) or the file gets renamed or deleted you might be reworking things inside ClearSCADA to get that data displayed again.

If all the name and phone number information is attached to users already in ClearSCADA you could just query ClearSCADA to display the info too. If the info changes I would expect the users in CLearSCADA to stay fairly up to date (for alarm redirections, etc.) so it should be a reliable source.

________________

**_hardin4019:
Spending a little time working through the suggestion from Dustin. Below is what I have, and I am getting an error message about "Access Denied"._**

_Sub InsertData()
Dim EmptyDB As Integer
Set ado = CreateObject("ADODB.Connection")
Set adoRS = CreateObject("ADODB.Recordset")
EmptyDB = 0
ado.Open "DSN=ClearSCADA", Training, 123456789123#
If ado.State = 1 Then
MsgBox "Connected"
End If
If EmptyDB = 1 Then
ado.Execute "DELETE FROM PhoneList2"
End If
queryText = "insert into PhoneList2 (Name, PhoneNumber, Address) values ('" & A$ & "', '" & B$ & "', '" & C$ & "')"
ado.Execute queryText
ado.Close
Set ado = Nothing
MsgBox "Done"
End Sub_

______________________________

du5tin:
I guess check to see if:

1. Your DSN is setup in both 32-bit and 64-bit ODBC control panels (I use the same name for both so it can be found no matter which architecture the ODBC client is)

2. Enclose your username and password in quotes (they are strings)

3. Check that you can log on using the user in ViewX (sounds silly, but sometimes the user is disabled or locked out).

__________________________________

**_I have both 32 bit and 64 bit ODBC connections setup. Using a username and password I am logging in with. I thought maybe it was happening because "logon as a service" wasn't enabled. But now after putting quotes around the username and password, I am getting the script to run, but still not seeing data in the table._**

__________

bevanweiss:
Where are you getting this error? (at which line)

I assume that it's ado.Open.
The syntax there looks a bit unusual, I guess I'm more used to putting the username and password within the ODBC / OLEDB connection string itself.

I'd generally do such development within Excel and VBA, then you can just migrate it into VBScript for ViewX/WebX pretty easily (just pulling out type definitions and a few other small items).


____________________

**_hardin4019:
I was getting "Access Denied" at row ado.Execute queryText. Now I put quotes around the username and password and I am no longer getting access denied, but nothing is being added to the table. So One step closer, but not quite there yet._**

_________________________

**_hardin4019:
[Solved] See code below for working version. Note its a good bit longer than some of the other posts and includes enough comments so people can figure it out and use it again._**

_Sub InsertData()
Dim EmptyDB, iRowNo As Integer
Dim Name, PhoneNumber, Address As String
'All of the data being inserted is in Sheet1
With Sheets("Sheet1")
Set ado = CreateObject("ADODB.Connection")
Set adoRS = CreateObject("ADODB.Recordset")
EmptyDB = 1
'Skip the header row with header info
iRowNo = 2
'Put in the DSN name, Username, Password below
ado.Open "DSN=ClearSCADA", "username", "password"
'Show message box if connected to DB.
'If ado.State = 1 Then
' MsgBox "Connected"
'End If
'Delete all of the data in the table if the EmptyDB equals 1
If EmptyDB = 1 Then
ado.Execute "DELETE FROM PhoneList"
End If
'Loop until empty row
Do Until .Cells(iRowNo, 1) = "" And .Cells(iRowNo, 2) = "" And .Cells(iRowNo, 3) = ""
sName = .Cells(iRowNo, 1)
sPhoneNumber = .Cells(iRowNo, 2)
sAddress = .Cells(iRowNo, 3)
'Build the query
queryText = "INSERT INTO PhoneList (Name, PhoneNumber, Address) VALUES ('" & sName & "', '" & sPhoneNumber & "', '" & sAddress & "')"
'Execute the query
ado.Execute queryText
'Increment iRowNo and repeat until empty row
iRowNo = iRowNo + 1
Loop
'Close DB connection and message done
ado.Close
Set ado = Nothing
MsgBox "Done"
End With
End Sub_

Labels
  • Labels:
  • SCADA
Reply
Contact Support

Link copied. Please paste this link to share this article on your social media post.

  • All forum topics
  • Previous Topic
  • Next Topic
Replies 0
To The Top!

Forums

  • APC UPS Data Center Backup Solutions
  • EcoStruxure IT
  • EcoStruxure Geo SCADA Expert
  • Metering & Power Quality
  • Schneider Electric Wiser

Knowledge Center

Events & webinars

Ideas

Blogs

Get Started

  • Ask the Community
  • Community Guidelines
  • Community User Guide
  • How-To & Best Practice
  • Experts Leaderboard
  • Contact Support
Brand-Logo
Subscribing is a smart move!
You can subscribe to this board after you log in or create your free account.
Forum-Icon

Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.

Register today for FREE

Register Now

Already have an account? Login

Terms & Conditions Privacy Notice Change your Cookie Settings © 2025 Schneider Electric

This is a heading

With achievable small steps, users progress and continually feel satisfaction in task accomplishment.

Usetiful Onboarding Checklist remembers the progress of every user, allowing them to take bite-sized journeys and continue where they left.

of