Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - Worksheet Coding Help

Hello,

i put a command button on the first sheet of a template workbook and i
is my intention to put data from a web query to another sheet in th
same workbook when i press the command button created on sheet1. th
code i have is as follows:

With ThisWorkbook.Worksheets("Sheet2").QueryTables.Add( Connection:= _
"URL;http://chart.yahoo.com/table.csv?a=...amp;ignore=.csv", _
Destination:=Range("a6"))

.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xloverwriteclearcells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
'.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingAll
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
.TextFileCommaDelimiter = True
End With

Range("A6:A7").Select
Selection.TextToColumns Destination:=Range("A6")
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False
_
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5
1), Array(6, 1), _
Array(7, 1))
Range("A7:G3").Select
Selection.Columns.AutoFit

i am getting the following error:

this destinationrange is not on the same worksheet that the query tabl
is being created on.

how should i modify my code and/or approch to achive my goal?

thank you for any help you can offer.

ton

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Excel VBA - Worksheet Coding Help

You need to qualify your ranges with a worksheet. Or
activate the second sheet so the implied "ActiveSheet"
will be used for your ranges.

I like to qualify them all, personally.

dim shtSheet2 as Worksheet
set shtSheet2 = Worksheets("Sheet2")

Then refer to shtSheet2.Range("A6")

-Brad

-----Original Message-----
Hello,

i put a command button on the first sheet of a template

workbook and it
is my intention to put data from a web query to another

sheet in the
same workbook when i press the command button created on

sheet1. the
code i have is as follows:

With ThisWorkbook.Worksheets("Sheet2").QueryTables.Add

(Connection:= _
"URL;http://chart.yahoo.com/table.csv?

a=...amp;ignore=.csv", _
Destination:=Range("a6"))

.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xloverwriteclearcells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
'.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingAll
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
.TextFileCommaDelimiter = True
End With

Range("A6:A7").Select
Selection.TextToColumns Destination:=Range("A6"),
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote,

ConsecutiveDelimiter:=False, Tab:=False,
_
Semicolon:=False, Comma:=True, Space:=False,

Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4,

1), Array(5,
1), Array(6, 1), _
Array(7, 1))
Range("A7:G3").Select
Selection.Columns.AutoFit

i am getting the following error:

this destinationrange is not on the same worksheet that

the query table
is being created on.

how should i modify my code and/or approch to achive my

goal?

thank you for any help you can offer.

tony


---
Message posted from http://www.ExcelForum.com/

.

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
How do I match numeric coding in a worksheet to words in a pdf fil Motown Mick Excel Discussion (Misc queries) 5 June 20th 07 01:06 AM
Customizing Excel Worksheet Menu Bar without VBA coding Sylvia Excel Discussion (Misc queries) 7 March 22nd 06 06:58 PM
Customizing Worksheet Menu Bar for a workbook without VBA coding Sylvia Excel Discussion (Misc queries) 0 March 20th 06 07:20 AM
Correct coding entry of VBA macros in Excel worksheet Jack R Excel Worksheet Functions 3 November 30th 05 11:00 AM
Referring to Previous Worksheet - coding Denis Excel Worksheet Functions 7 December 10th 04 05:24 PM


All times are GMT +1. The time now is 05:11 PM.

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

About Us

"It's about Microsoft Excel"