Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Write to closed workbook code

I was doing a search in Google Groups for code that will write data to a
closed workbook and found this. I am trying to write data to cell A1 of
C:\test.xls. I do not know how to really use databases so this code is very
hard for me. Can anyone please tell me what I need to do to get this to
write lets say "test" to cell A1 of C:\test.xls? This code fails when it
gets to the line: objConn.Execute szSQL, , adCmdText Or
adExecuteNoRecords. I get error Run Time error '-2147217900 (80040e14)':
Automation error. Any help is greatly appreciated.


Thank you

Dim objConn As ADODB.Connection
Dim szConnect As String
Dim szSQL As String
' Create the connection string.
szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\test.xls;" & _
"Extended Properties=Excel 8.0;"
' Create the SQL statement.
szSQL = "INSERT INTO <BookLevelName " & _
"VALUES('Val1', 'Val2', Val3, Val4);"
' Create and open the Connection object.
Set objConn = New ADODB.Connection
objConn.Open szConnect
' Execute the insert statement.
objConn.Execute szSQL, , adCmdText Or adExecuteNoRecords
' Close and destroy the Connection object.
objConn.Close
Set objConn = Nothing

Todd Huttenstine


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Write to closed workbook code

What does your szSQL string look like?

does it look like the one you posted:

szSQL = "INSERT INTO <BookLevelName " & _
"VALUES('Val1', 'Val2', Val3, Val4);"


If so, you need to define a name and put it in there.

--
Regards,
Tom Ogilvy






"Todd Huttenstine" wrote in message
...
I was doing a search in Google Groups for code that will write data to a
closed workbook and found this. I am trying to write data to cell A1 of
C:\test.xls. I do not know how to really use databases so this code is

very
hard for me. Can anyone please tell me what I need to do to get this to
write lets say "test" to cell A1 of C:\test.xls? This code fails when it
gets to the line: objConn.Execute szSQL, , adCmdText Or
adExecuteNoRecords. I get error Run Time error '-2147217900 (80040e14)':
Automation error. Any help is greatly appreciated.


Thank you

Dim objConn As ADODB.Connection
Dim szConnect As String
Dim szSQL As String
' Create the connection string.
szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\test.xls;" & _
"Extended Properties=Excel 8.0;"
' Create the SQL statement.
szSQL = "INSERT INTO <BookLevelName " & _
"VALUES('Val1', 'Val2', Val3, Val4);"
' Create and open the Connection object.
Set objConn = New ADODB.Connection
objConn.Open szConnect
' Execute the insert statement.
objConn.Execute szSQL, , adCmdText Or adExecuteNoRecords
' Close and destroy the Connection object.
objConn.Close
Set objConn = Nothing

Todd Huttenstine




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Write to closed workbook code

What do you mean? I do not know what BookLevelName means.

Can you please explain?



"Tom Ogilvy" wrote in message
...
What does your szSQL string look like?

does it look like the one you posted:

szSQL = "INSERT INTO <BookLevelName " & _
"VALUES('Val1', 'Val2', Val3, Val4);"


If so, you need to define a name and put it in there.

--
Regards,
Tom Ogilvy






"Todd Huttenstine" wrote in message
...
I was doing a search in Google Groups for code that will write data to a
closed workbook and found this. I am trying to write data to cell A1 of
C:\test.xls. I do not know how to really use databases so this code is

very
hard for me. Can anyone please tell me what I need to do to get this to
write lets say "test" to cell A1 of C:\test.xls? This code fails when

it
gets to the line: objConn.Execute szSQL, , adCmdText Or
adExecuteNoRecords. I get error Run Time error '-2147217900

(80040e14)':
Automation error. Any help is greatly appreciated.


Thank you

Dim objConn As ADODB.Connection
Dim szConnect As String
Dim szSQL As String
' Create the connection string.
szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\test.xls;" & _
"Extended Properties=Excel 8.0;"
' Create the SQL statement.
szSQL = "INSERT INTO <BookLevelName " & _
"VALUES('Val1', 'Val2', Val3, Val4);"
' Create and open the Connection object.
Set objConn = New ADODB.Connection
objConn.Open szConnect
' Execute the insert statement.
objConn.Execute szSQL, , adCmdText Or adExecuteNoRecords
' Close and destroy the Connection object.
objConn.Close
Set objConn = Nothing

Todd Huttenstine






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Write to closed workbook code

Insert = Name = Define

Name: MyName
Refers to: =Sheet1!$A$1

--
Regards,
Tom Ogilvy

"Todd Huttenstine" wrote in message
...
What do you mean? I do not know what BookLevelName means.

Can you please explain?



"Tom Ogilvy" wrote in message
...
What does your szSQL string look like?

does it look like the one you posted:

szSQL = "INSERT INTO <BookLevelName " & _
"VALUES('Val1', 'Val2', Val3, Val4);"


If so, you need to define a name and put it in there.

--
Regards,
Tom Ogilvy






"Todd Huttenstine" wrote in message
...
I was doing a search in Google Groups for code that will write data to

a
closed workbook and found this. I am trying to write data to cell A1

of
C:\test.xls. I do not know how to really use databases so this code

is
very
hard for me. Can anyone please tell me what I need to do to get this

to
write lets say "test" to cell A1 of C:\test.xls? This code fails when

it
gets to the line: objConn.Execute szSQL, , adCmdText Or
adExecuteNoRecords. I get error Run Time error '-2147217900

(80040e14)':
Automation error. Any help is greatly appreciated.


Thank you

Dim objConn As ADODB.Connection
Dim szConnect As String
Dim szSQL As String
' Create the connection string.
szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\test.xls;" & _
"Extended Properties=Excel 8.0;"
' Create the SQL statement.
szSQL = "INSERT INTO <BookLevelName " & _
"VALUES('Val1', 'Val2', Val3, Val4);"
' Create and open the Connection object.
Set objConn = New ADODB.Connection
objConn.Open szConnect
' Execute the insert statement.
objConn.Execute szSQL, , adCmdText Or adExecuteNoRecords
' Close and destroy the Connection object.
objConn.Close
Set objConn = Nothing

Todd Huttenstine








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Write to closed workbook code

Worth pointing out that it doesn't have to be a book level name e.g.

INSERT INTO [BookLevelName] (MyCol1, MyCol2) VALUES (1,2)

It can also be a sheet level name e.g.

INSERT INTO [Sheet1$SheetLevelName] (MyCol1, MyCol2) VALUES (1,2)

or a worksheet name e.g.

INSERT INTO [Sheet1$] (MyCol1, MyCol2) VALUES (1,2)

or a range address e.g.

INSERT INTO [Sheet1$A1:B999] (MyCol1, MyCol2) VALUES (1,2)

--

"Tom Ogilvy" wrote in message ...
Insert = Name = Define

Name: MyName
Refers to: =Sheet1!$A$1

--
Regards,
Tom Ogilvy

"Todd Huttenstine" wrote in message
...
What do you mean? I do not know what BookLevelName means.

Can you please explain?



"Tom Ogilvy" wrote in message
...
What does your szSQL string look like?

does it look like the one you posted:

szSQL = "INSERT INTO <BookLevelName " & _
"VALUES('Val1', 'Val2', Val3, Val4);"

If so, you need to define a name and put it in there.

--
Regards,
Tom Ogilvy






"Todd Huttenstine" wrote in message
...
I was doing a search in Google Groups for code that will write data to

a
closed workbook and found this. I am trying to write data to cell A1

of
C:\test.xls. I do not know how to really use databases so this code

is
very
hard for me. Can anyone please tell me what I need to do to get this

to
write lets say "test" to cell A1 of C:\test.xls? This code fails when

it
gets to the line: objConn.Execute szSQL, , adCmdText Or
adExecuteNoRecords. I get error Run Time error '-2147217900

(80040e14)':
Automation error. Any help is greatly appreciated.


Thank you

Dim objConn As ADODB.Connection
Dim szConnect As String
Dim szSQL As String
' Create the connection string.
szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\test.xls;" & _
"Extended Properties=Excel 8.0;"
' Create the SQL statement.
szSQL = "INSERT INTO <BookLevelName " & _
"VALUES('Val1', 'Val2', Val3, Val4);"
' Create and open the Connection object.
Set objConn = New ADODB.Connection
objConn.Open szConnect
' Execute the insert statement.
objConn.Execute szSQL, , adCmdText Or adExecuteNoRecords
' Close and destroy the Connection object.
objConn.Close
Set objConn = Nothing

Todd Huttenstine








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help...Code to copy sheet from closed workbook [email protected] Excel Discussion (Misc queries) 1 March 28th 07 08:52 PM
copy worksheet from closed workbook to active workbook using vba mango Excel Worksheet Functions 6 December 9th 04 07:55 AM
Code that retrieves values from a closed workbook Todd Huttenstine Excel Programming 1 April 28th 04 07:34 PM
Code for Opening a Closed Workbook scrabtree23[_2_] Excel Programming 3 November 11th 03 03:48 PM
Write to Array from other closed Excel file Dave B[_4_] Excel Programming 5 October 1st 03 04:48 PM


All times are GMT +1. The time now is 03:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"