Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / May 2008

Tip: Looking for answers? Try searching our database.

Error 424 for sample code?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Taras_96 - 24 May 2008 14:00 GMT
Hi all,

I'm new to VBA programming, and I'm trying to run the code found at:
http://www.microsoft.com/technet/scriptcenter/resources/officetips/may05/tips050
3.mspx


Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)

objExcel.Cells(1, 1).Value = "Olympia, WA"
objExcel.Cells(2, 1).Value = "Salem, OR"
objExcel.Cells(3, 1).Value = "Boise, ID"
objExcel.Cells(4, 1).Value = "Sacramento, CA"

Set objRange = objExcel.Range("A1").EntireColumn
Set objRange2 = objExcel.Range("B1")

objRange.TextToColumns objRange2,,,,,,TRUE

When I click on run, I get a 424 error, and clicking on debug sends me
to the last line. What is wrong with the code?

Thanks

Taras
Dave Peterson - 24 May 2008 14:56 GMT
The code worked ok for me (xl2003).

But I would have used:

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)

objWorksheet.Cells(1, 1).Value = "Olympia, WA"
objWorksheet.Cells(2, 1).Value = "Salem, OR"
objWorksheet.Cells(3, 1).Value = "Boise, ID"
objWorksheet.Cells(4, 1).Value = "Sacramento, CA"

Set objRange = objWorksheet.Range("A1").EntireColumn
Set objRange2 = objWorksheet.Range("B1")

objRange.TextToColumns objRange2, , , , , , True

> Hi all,
>
[quoted text clipped - 22 lines]
>
> Taras

Signature

Dave Peterson

Rick Rothstein (MVP - VB) - 24 May 2008 15:38 GMT
I'd like to point out for the OP that the webpage where he got that code was
for VBScript (not VBA) which is what necessitated the need to create the
Excel application (the first 4 lines of code). When performing the same
functionality inside of Excel, you can execute the code directly within the
Excel session you are currently in (and eliminate the first four lines of
code and, as an aside, we can eliminate the objRange and objRange2 Set
statements by working with the given Ranges directly). So, assuming the OP
did not really need to create a new workbook for some other reason, I would
have written the code something like this...

With Worksheets("Sheet1")
 .Cells(1, 1).Value = "Olympia, WA"
 .Cells(2, 1).Value = "Salem, OR"
 .Cells(3, 1).Value = "Boise, ID"
 .Cells(4, 1).Value = "Sacramento, CA"
 .Range("A1").EntireColumn.TextToColumns .Range("B1"), , , , , , True
End With

so the only significant code to pay attention to is that last line inside
the With/End With block (the rest simply creating the data for that last
line to operate on). I would also note that all of the state abbreviations
were placed in Column C with leading space characters, so code to eliminate
them would probably be necessary later on.

Rick

> The code worked ok for me (xl2003).
>
[quoted text clipped - 41 lines]
>>
>> Taras
Taras_96 - 26 May 2008 00:37 GMT
Hmmm, now it works fine ?! Thanks for the tips regarding the creation
of the new excel document - you were correct in guessing that I didn't
want to create a new worksheet :)

Taras
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.