LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default click an internet pop-up "OK" button

I have coded a program that takes the ticker symbols from one
worksheet(1) [i.e. A1 = ticker1, A2 = ticker2....], gets the pricing
information from Yahoo!Finance and inputs it into another
worksheet(2), runs a calculation based off the pricing information,
and copies and pastes the output to another worksheet(3). When the
calculation is complete the computer clears out the pricing
information from worksheet(2) and moves to the next ticker symbol.

The problem however is that if Yahoo!Finance does NOT have pricing
information for the specified ticker, a small message box pops up that
reads "Could not open "http://ichart.finance.yahoo.com/table.csv?
s= ......." When I click "OK" the program execution returns "Run-time
error '1004': Microsoft Office Excel cannot access the file 'http://
ichart.....' There are serveral possible reasons:....."

I want to know if there is a way to click the pop-up "OK" button for
the "Could not open...." message box. I could write an "On Error"
statement to catch the end/debug window after clicking "OK", but I
don't know how to get passed the "Could not open...." message box. (I
want to run this on several ticker symbols, and it would be a pain to
have to manually click the "OK" button each time this type of
situation occurs).

I have included my code below. A list of tickers that work as
expected are the following: JNJ, ADBE, APOL, LLTC. A list of tickers
that produce the "Could not open...." message box are the following:
RMK, HCA, RUSMF, ITWG.

Any help is appreciated. Thanks in advance. (Also, make sure that
VBE: Tools/References/Microsoft Forms 2.0 Object Library is selected).

Option Explicit
Sub yahooCSV2()
Dim a 'start month
Dim b 'start day
Dim c 'start year
Dim d 'end month
Dim e 'end day
Dim f 'end year
Dim tic 'ticker
Dim mon 'month
Dim dy 'day
Dim yr 'year
Dim wbCSV 'workbook CSV
Dim wbPT 'workbook Pricing Tool
Dim counter 'counter for the loop
Dim outputCounter 'counter for the output
Dim answer 'value of calculation
Dim m 'marker for the loop
Dim myData As DataObject 'to clear the clipboard

Set myData = New DataObject

wbCSV = "table.csv"
wbPT = ActiveWorkbook.Name

Worksheets(1).Select
counter = Range("a1").CurrentRegion.Rows.Count

For m = 1 To counter
tic = Worksheets(1).Range("a" & m).Value

mon = Format(DateSerial(Year(Date), Month(Date), Day(Date)), "mmm")
dy = Format(DateSerial(Year(Date), Month(Date), Day(Date)), "dd")
yr = Format(DateSerial(Year(Date), Month(Date), Day(Date)), "yyyy")

a = monthToNumber(mon)
b = dy
c = yr - 10

d = a
e = b
f = yr

Workbooks.Open Filename:="http://ichart.finance.yahoo.com/table.csv?
s=" _
& tic & "&a=" & a & "&b=" & b & "&c=" & c &
"&d=" _
& d & "&e=" & e & "&f=" & f &
"&g=d&ignore=.csv"

Workbooks(wbPT).Worksheets(2).Range("a1").CurrentR egion.ClearContents
Workbooks(wbCSV).Activate
Range("a1").CurrentRegion.Copy
Workbooks(wbPT).Worksheets(2).Range("a1").PasteSpe cial

myData.SetText ""
myData.PutInClipboard

Workbooks(wbCSV).Close savechanges:=False

Workbooks(wbPT).Activate
outputCounter = Worksheets(3).Range("a1").CurrentRegion.Rows.Count
answer = Worksheets(2).Range("j1").Value
Worksheets(3).Range("a" & outputCounter + 1).Value = tic
Worksheets(3).Range("b" & outputCounter + 1).Value = answer
Next

End Sub

Private Function monthToNumber(ByVal mon)

Select Case mon
Case "Jan"
monthToNumber = Right(100, 2)
Case "Feb"
monthToNumber = Right(101, 2)
Case "Mar"
monthToNumber = Right(102, 2)
Case "Apr"
monthToNumber = Right(103, 2)
Case "May"
monthToNumber = Right(104, 2)
Case "Jun"
monthToNumber = Right(105, 2)
Case "Jul"
monthToNumber = Right(106, 2)
Case "Aug"
monthToNumber = Right(107, 2)
Case "Sep"
monthToNumber = Right(108, 2)
Case "Oct"
monthToNumber = Right(109, 2)
Case "Nov"
monthToNumber = Right(110, 2)
Case "Dec"
monthToNumber = Right(111, 2)
End Select

End Function

 
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
Click on cell (or "button"), takes you to appropriate information ahwelch Excel Worksheet Functions 1 June 3rd 09 08:13 PM
"Next" button for reading NG from Internet Khoshravan New Users to Excel 7 February 1st 09 12:00 PM
Excel forms button "click" Jeff Excel Programming 1 September 9th 05 09:30 PM
how to stop program with loop by click "Cancel" button miao jie Excel Programming 2 December 16th 04 02:42 PM
commnd button - when i rt click, "assign macro" isnt an option... kevin[_3_] Excel Programming 1 November 12th 04 09:52 PM


All times are GMT +1. The time now is 10:15 PM.

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"