LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Not getting the object structure of VBA Excel

I have modified it to accept arguments to the connection string so you get
Today's data.
I also set the Backgroundquery = False parameter so the query is completed
before your code continues so you don't need the While . . . Wend loop.

Sub Workbook_Open()

Dim mMonth As String
Dim mDayStart As String
Dim mDayEnd As String
Dim mYear As String
Dim mConnectionString As String
Dim dinky As QueryTable

mYear = Format(Year(Now), "0000")
mMonth = Format(Month(Now), "00")
mDayEnd = Format(Day(Now), "00") & "00"
mDayStart = Format(Day(Now), "00") & "00"
Sheet1.Columns.Clear

mConnectionString = "URL;http://weather.uwyo.edu/" & _
"cgi-bin/sounding?region=naconf&TYPE=TEXT%3ALIST&"
mConnectionString = mConnectionString & _
"YEAR=" & mYear & _
"&MONTH=" & mMonth & _
"&FROM=" & mDayStart & _
"&TO=" & mDayEnd & _
"&STNM=72365"
' Debug.Print mConnectionString

Set dinky = Sheet1.QueryTables.Add(mConnectionString,
Application.Range("A2"))

With dinky
.WebSelectionType = xlSpecifiedTables
.WebTables = "1"
.WebPreFormattedTextToColumns = True
.BackgroundQuery = False
.Refresh
End With

Sheet1.Columns(1).Delete
End Sub


--
Regards,
Tom Ogilvy


"Paul" wrote in message
news:gFbKd.11232$rw.9027@fed1read04...
Tom Ogilvy wrote:
I don't understand the question and the only code you provided was the

one
line.

I don't see how the workbook_open event fits into this scenario you
describe:


For instance I import some data into the first sheet, then I try to
delete the first column, since I don't need the data,



Seems like deleting a column would occur after the workbook_open had
completed.


Tom,

I am new to programming excel, please forgive my ignorance. Basically
what I am trying to do is load data into a work sheet from a website.
After the data is loaded, I intend to then reformat it, delete un needed
data columns, convert meters to feet etc. My thought is to do all this
in the workbook open event, to use that as the master control for the
whole program. Below is my code so far, I think this will give you a
better perspective on what's going on

Private Sub Workbook_Open()

Dim mMonth
Dim mDay
Dim mYear


mYear = year(FormatDateTime(Now, vbShortDate))
mMonth = month(FormatDateTime(Now, vbShortDate))
mDay = day(FormatDateTime(Now, vbShortDate))

Sheet1.Columns.Clear

Dim dinky As QueryTable
mConnectionString =

"URL;http://weather.uwyo.edu/cgi-bin/soun...PE=TEXT%3ALIST
&"
mConnectionString = mConnectionString +
"YEAR=2005&MONTH=01&FROM=2700&TO=2700&STNM=723 65"

Set dinky =
Sheet1.QueryTables.Add(mConnectionString,Applicati on.Range("A2:Z2"))

While dinky.Refreshing
'do nothing
Wend

With dinky

.WebSelectionType = xlSpecifiedTables
.WebTables = "1"
.WebPreFormattedTextToColumns = True
.Refresh

End With

'once data is loaded into the page, start cleaning it up i.e.
'ThisWorkbook.Sheets(1).Columns(1).delete

End Sub



 
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
cant pass array to excel from c++ using xloper structure malayhk Excel Worksheet Functions 0 November 4th 09 09:09 AM
excel outlines structure meghnal Excel Discussion (Misc queries) 3 June 27th 09 07:28 AM
Protect an Excel 2007 workbook structure Austrian Hannes Excel Discussion (Misc queries) 2 March 19th 08 03:21 PM
Analyze Excel files structure Ramon N. Gene Excel Programming 0 August 4th 04 10:55 PM
Analyze Excel files structure Ramon Excel Programming 0 August 4th 04 08:55 PM


All times are GMT +1. The time now is 05:29 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"