svae Workbooks.Open as new worksheet

marc005

Board Regular
Joined
Apr 21, 2013
Messages
58
The VBA code to download my csv from my account at dropbox is:

Sub OpenCSVDropbox()
Workbooks.Open Filename:= _
"http://bit.ly/15YwK10"
End Sub

However, a new workbook is always open. I want a new worksheet in the current workbook named "data1"
to open not a new workbook.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I have tried:

Sub OpenCSVDropbox()
Workbooks.Open Filename:= _
"http://bit.ly/15YwK10" & "data1"
End Sub

but that does not work he he
 
Upvote 0
try:
Code:
Sub OpenCSVDropbox()
Set xx = Workbooks.Open(Filename:="http://bit.ly/15YwK10").Sheets(1)
xx.Name = "data1"
xx.Move After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
End Sub
 
Upvote 0
thanx for your input but it did not work :-( Excel opens a new workbook as usual hummm
Yes, but it get's closed when the sheet is moved. Is that a problem? You get your new sheet, correctly named,added to the existing workbook.
 
Upvote 0
I get an error from the line marked with bold below:

Sub OpenCSVDropbox()
Set xx = Workbooks.Open(Filename:="http://bit.ly/15YwK10").Sheets(1)
xx.Name = "data1"
xx.Move After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
End Sub

the worksheet is never added to the existing workbook it is created in a new workbook. sorry if I am being a picky.
 
Upvote 0
Where have you put this code? In the Personal workbook? Put it into the workbook you want to have the sheet added to, in a standard code-module.

Or,

try
Code:
Sub OpenCSVDropbox()
Set yy = ActiveWorkbook
Set xx = Workbooks.Open(Filename:="http://bit.ly/15YwK10").Sheets(1)
xx.Name = "data1"
xx.Move After:=yy.Sheets(yy.Sheets.Count)
End Sub
 
Upvote 0
thanx for your patient with me :-) Yeahhh I put it in personal (old habit). sorry for that.
By the way your last code works great :-) and most likely the first one too if I just manage to put it in the right place he he
Thanx for your help. It saved me loads of time :-)
 
Upvote 0
Or a different approach, though fraught with dangers:
Code:
Sub Macro8()
Set newsht = ActiveWorkbook.Worksheets.Add
Set qry = newsht.QueryTables.Add(Connection:="TEXT;http://bit.ly/15YwK10", Destination:=Range("A1"))
With qry
  .FieldNames = True
  .RowNumbers = False
  .FillAdjacentFormulas = False
  .PreserveFormatting = True
  .RefreshOnFileOpen = False
  .RefreshStyle = xlInsertDeleteCells
  .SavePassword = False
  .SaveData = True
  .AdjustColumnWidth = True
  .RefreshPeriod = 0
  .TextFilePromptOnRefresh = False
  .TextFilePlatform = 850
  .TextFileStartRow = 1
  .TextFileParseType = xlDelimited
  .TextFileTextQualifier = xlTextQualifierDoubleQuote
  .TextFileConsecutiveDelimiter = False
  .TextFileTabDelimiter = False
  .TextFileSemicolonDelimiter = False
  .TextFileCommaDelimiter = True
  .TextFileSpaceDelimiter = False
  .TextFileTrailingMinusNumbers = True
  .Refresh BackgroundQuery:=False
End With
qry.Delete
newsht.Name = "data1"
newsht.Move after:=newsht.Parent.Sheets(newsht.Parent.Sheets.Count)
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top