logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
StorkBite  
#1 Posted : Sunday, June 4, 2006 10:52:37 PM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
The following Excel Macro will convert the IBD XLS file into a MS SYM file automatically and save it in the Downloader directory. It creates a unique file for each date, but will overwrite an existing SYM file if the macro is run on the same set of data more than once. It does not adjust your original XLS file in any way. Feedback is welcome! Note: You will need to modify the 'targetFile' path to reflect your Downloader path. Note: You will need to modify the 'Selection.FormulaR1C1' line to remove the "us;" prefix if you do not receive QC data. [code:1:176658599e] Sub IBDConversion() ' Convert Investors Business Daily XLS to MetaSock SYM ' Written by G. Stockman, 2004-2006. All rights reserved. ' Updated: June 4, 2006 @ 2050 CST ' Supress screen updates Application.ScreenUpdating = False ' Remember date of market close Dim dString As String dString = Range("A2").Value Dim strSplit() As String strSplit = Split(dString, " ") dString = strSplit(3) ' Format date (remove string separators) Dim pos As Integer pos = InStr(dString, "/") dString = Left(dString, pos - 1) & Mid(dString, pos + 1) pos = InStr(dString, "/") dString = Left(dString, pos - 1) & Mid(dString, pos + 1) ' Copy raw source data to a new workbook Range("B7:C106").Select Selection.Copy Workbooks.Add ActiveSheet.Paste ' Create SYM compatible template Range("A1:A100").Select Selection.EntireColumn.Insert Selection.FormulaR1C1 = "=RC[1] & "","" & ""us;"" & RC[2] & "","" & ""N/A"" & "","" & ""0"" & "","" & ""0""" Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False ' Delete raw source code Columns("B:C").Select Selection.Delete ' Save new SYM file Dim targetFile As String targetFile = "C:\\Program Files\\Equis\ he DownLoader\\ibd100_" & dString & ".sym" Application.DisplayAlerts = False ActiveWorkbook.SaveAs Filename:=targetFile, FileFormat:=xlTextPrinter, CreateBackup:=False Application.DisplayAlerts = True ' Close temporary workbook ActiveWorkbook.Close False Range("A1").Select ' Resume screen updates Application.ScreenUpdating = True ' Completion alert MsgBox ("Conversion completed!") End Sub [/code:1:176658599e] Convert the XLS data: UserPostedImage To SYM data: UserPostedImage
StorkBite  
#2 Posted : Wednesday, June 28, 2006 8:00:46 AM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
To use the macro above, you should roughly follow the steps listed below. There are other means, but this outline is pretty easy. *** STEP 1 *** TOOLS | MACRO | RECORD NEW MACRO In the 'Macro Name' box put "IBDConversion" In the 'Store Macro In' box select "Personal Macro Workbook" Select OK, then immediately press the STOP RECORDING button Start the VB Editor by pressing ALT-F11 In the Project Window on the left side of the screen, you will see a heading called "VBAProject (PERSONAL.XLS)" Click on the MODULES folder and then on MODULE1 You should now see a blank "IBDConversion" macro listed. Overwrite the blank code with the macro I posted on the forum. Press CTRL-S to save PERSONAL.XLS. Close the VB Editor. *** STEP 2 *** Open the UNMODIFIED IBD100 XLS file that you downloaded from Investors.com. Press ALT-F8 to run the IBDConversion macro. If necessary, select the macro location as "Personal.xls" Done! *** TROUBLESHOOTING *** I have not tested this on any version other than Excel 2003. If you are getting errors, please post them here. This macro will only work with an original, unmodified IBD XLS file. If you are unsure, look at this picture to make sure your format looks like mine. These files are available to IBD subscribers by clicking here: Weekly IBD100 The following link is not a part of this thread, but is also a good resource for IBD subscribers: CANSLIM Select
ericsonk  
#3 Posted : Thursday, July 27, 2006 11:55:32 PM(UTC)
ericsonk

Rank: Newbie

Groups: Registered, Registered Users
Joined: 4/22/2006(UTC)
Posts: 5

Just tried to run the IBDConversion script -- Error Msg from Microsoft Visual Basic: Run-time error '1004'; Method 'Add' of object 'Workbooks' failed. THEN-I figured out that I should have SAVED the IBD100 spreadsheet to an *.xls file on my PC, and not try to convert the spreadsheet that was displayed in the HTML window to the *.sym file. Hope that helps if anyone runs into the same issue.
wabbit  
#4 Posted : Friday, July 28, 2006 12:05:35 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Just adding as to why this happens... its a tip for any budding Excel programmers. The "Workbooks" collection is a member of the Applicaton. If a customer is viewing the spreadseheet/workbook in Excel, the current application object is Excel, so all the objects, mthods, colectons etc normally associated with this application object can be called, moved, added, deleted etc. If the user is viewing the worksheet in a browser because they have just downloaded the data from your webserver etc then the current application is the browser, not Excel. This means that only objects and collections that are members of the browser application can be manipulated. I once built a page for a friend who distributed it on the web and was inundated by calls from his clients who said the product didn't work! I was left dealing with an unhappy customer... The answer is to check what is the current application at the start of the VBA code and exit if it isn't what is expected. From the MSDN... Set myObject = ActiveWorkbook If myObject.Application.Value = "Microsoft Excel" Then MsgBox "This is an Excel Application object." Else MsgBox "This is not an Excel Application object." End If Hope this helps. wabbit :D
StorkBite  
#5 Posted : Friday, July 28, 2006 1:23:09 AM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
Thanks, Wabbit. I'll add this step to my next revision. I think Eric's feedback is great, cause it allows me to make the code all the more bulletproof. You know I appreciate your help (as always). :)
ericsonk  
#6 Posted : Saturday, July 29, 2006 2:54:47 PM(UTC)
ericsonk

Rank: Newbie

Groups: Registered, Registered Users
Joined: 4/22/2006(UTC)
Posts: 5

Wabbit, that's cool info...THANKS! I ran into a few snags though... I just added that code to the beginning of my macro script -- then tried it out viewing the IBD100 through my browser. The "this is an Excel Application" msg came up --which I had to respond to by clicking OK button so that the macro would continue... Then I got the same Run-time error '1004' msg 1) did I place the code incorrectly? 2) it would probably be better to ONLY have the error msg "NOT an Excel application' show up if Excel isn't running so that clicking the OK button isn't required to advance the macro... how should I correctly place improved coding?
StorkBite  
#7 Posted : Saturday, July 29, 2006 7:51:06 PM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
The original code is not ready to anticipate all possible errors since I developed it to meet my own requirements. In order for this function to work properly, a worksheet must be active in Excel. Wabbit's code is the foundation for doing something aside from reporting the error. e.g., if the worksheet is not active in Excel, start Excel and copy the online data. I will develop this soon. [code:1:4dae22e9d2]Sub IBDConversion() ' Convert local Investors Business Daily XLS to MetaSock SYM ' Written by G. Stockman, 2004. All rights reserved. ' Updated: July 29, 2006 @ 1430 CST ' Error handler On Error GoTo ErrorHandler ' Supress screen updates Application.ScreenUpdating = False ' Remember date of market close Dim dString As String dString = Range("A2").Value Dim strSplit() As String strSplit = Split(dString, " ") dString = strSplit(3) ' Format date (remove string separators) Dim pos As Integer pos = InStr(dString, "/") dString = Left(dString, pos - 1) & Mid(dString, pos + 1) pos = InStr(dString, "/") dString = Left(dString, pos - 1) & Mid(dString, pos + 1) ' Copy raw source data to a new workbook Range("B7:C106").Select Selection.Copy Workbooks.Add ActiveSheet.Paste ' Create SYM compatible template Range("A1:A100").Select Selection.EntireColumn.Insert Selection.FormulaR1C1 = "=RC[1] & "","" & ""us;"" & RC[2] & "","" & ""N/A"" & "","" & ""0"" & "","" & ""0""" Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False ' Delete raw source code Columns("B:C").Select Selection.Delete ' Save new SYM file Dim targetFile As String targetFile = "C:\\Program Files\\Equis\ he DownLoader\\ibd100_" & dString & ".sym" Application.DisplayAlerts = False ActiveWorkbook.SaveAs Filename:=targetFile, FileFormat:=xlTextPrinter, CreateBackup:=False Application.DisplayAlerts = True ' Close temporary workbook ActiveWorkbook.Close False Range("A1").Select ' Resume screen updates Application.ScreenUpdating = True ' Completion alert MsgBox ("Conversion completed!") ' Exit macro normally Exit Sub ' Handle abnormal situations ErrorHandler: Dim Response As Integer Response = -1 Dim ErrorMsg01 As String ErrorMsg01 = "Local IBD XLS file cannot be found!" Dim ErrorMsg99 As String ErrorMsg99 = "The following unexpected error has occurred: " Select Case Err.Number Case 1004 If Err.Description = "Method 'Add' of object 'Workbooks' failed" Then Response = MsgBox(ErrorMsg01 & vbNewLine, _ vbOKOnly + vbCritical, "Error: 1004") Exit Sub Else Response = MsgBox(ErrorMsg99 & vbNewLine & vbNewLine & Err.Description, _ vbOKOnly + vbCritical, "Error: 1004") Exit Sub End If Case Else Response = MsgBox(ErrorMsg99 & vbNewLine & vbNewLine & Err.Description, _ vbOKOnly + vbCritical, "Unexpected Error") Exit Sub End Select End Sub[/code:1:4dae22e9d2]
wabbit  
#8 Posted : Monday, July 31, 2006 12:21:53 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Can someone please post a test file for the source data? I would like to do a little bit of coding to answer a couple of questions for myself about the application trapping, and help G out as he is busy with the migration. TIA wabbit :D
StorkBite  
#9 Posted : Thursday, August 3, 2006 3:25:08 PM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
Wow. I think it's a compliment that one's work gets public attention. I sorta feel like I'm on stage in my underwear. [:$]
Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.