Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Don't save external data.

Hi, I have a workbook that imports data from a folder containing .csv
files and puts the data from each csv file into a new sheet. What I
want to do is save the workbook and retain the sheets and the code that
fetches the external data, but not actually save the external data. Is
that possible? Here's what I have right now:

Code to create worksheets and import data from csv files. Note I use a
list of filenames in column B starting on row 6 on sheet "Files"

Function GetData()
Dim rng As Range, i As Long
Dim symbol As String
Application.DisplayAlerts = False
Application.ScreenUpdating = False
i = 6
Set rng = Cells(i, 2)
Do While Application.CountA(rng.Resize(1, 15)) < 0
symbol = Cells(i, 2).Value
Call import(symbol)
i = i + 1
Set rng = rng.Offset(1, 0)
Loop
End Function

Sub import(symbol)
Dim savepath As String
ActiveWorkbook.Worksheets.Add
ActiveSheet.Name = symbol
savepath = ThisWorkbook.path & "\Data\" & symbol & ".csv"
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" &
savepath, _
Destination:=Range("A1"))
.Name = symbol
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Sheets("Files").Select
End Sub

I know I'll need to remove the code that creates new sheets, as I want
to save the created sheets (but not the external data thats in them).

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Don't save external data.

I guess there is a reason you want to bring in the data even though you
don't want to save it (otherwise, you wouldn't need to bring it in)

Function GetData()
Dim rng As Range, i As Long
Dim symbol As String
Application.DisplayAlerts = False
Application.ScreenUpdating = False
i = 6
Set rng = Cells(i, 2)
Do While Application.CountA(rng.Resize(1, 15)) < 0
symbol = Cells(i, 2).Value
Call import(symbol)
i = i + 1
Set rng = rng.Offset(1, 0)
Loop

' do something with the sheets

i = 6
Set rng = Cells(i, 2)
Do While Application.CountA(rng.Resize(1, 15)) < 0
symbol = Cells(i, 2).Value
worksheets(symbol).Cells.Clear
i = i + 1
Set rng = rng.Offset(1, 0)
Loop
End Function

--
Regards,
Tom Ogilvy

"Nick" wrote in message
ups.com...
Hi, I have a workbook that imports data from a folder containing .csv
files and puts the data from each csv file into a new sheet. What I
want to do is save the workbook and retain the sheets and the code that
fetches the external data, but not actually save the external data. Is
that possible? Here's what I have right now:

Code to create worksheets and import data from csv files. Note I use a
list of filenames in column B starting on row 6 on sheet "Files"

Function GetData()
Dim rng As Range, i As Long
Dim symbol As String
Application.DisplayAlerts = False
Application.ScreenUpdating = False
i = 6
Set rng = Cells(i, 2)
Do While Application.CountA(rng.Resize(1, 15)) < 0
symbol = Cells(i, 2).Value
Call import(symbol)
i = i + 1
Set rng = rng.Offset(1, 0)
Loop
End Function

Sub import(symbol)
Dim savepath As String
ActiveWorkbook.Worksheets.Add
ActiveSheet.Name = symbol
savepath = ThisWorkbook.path & "\Data\" & symbol & ".csv"
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" &
savepath, _
Destination:=Range("A1"))
.Name = symbol
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Sheets("Files").Select
End Sub

I know I'll need to remove the code that creates new sheets, as I want
to save the created sheets (but not the external data thats in them).



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Don't save external data.

Okay, thanks. Problem with that is that I've put other data in those
sheets that isn't from the csv file that I want to keep, and
worksheets(symbol).Cells.Clear would delete it. I've found another way
I think:

Dim rng As Range, i As Long
Dim symbol As String
Application.DisplayAlerts = False
Application.ScreenUpdating = False
i = 6
Set rng = Cells(i, 2)
Do While Application.CountA(rng.Resize(1, 15)) < 0
symbol = Cells(i, 2).Value
Sheets(symbol).Select
Application.Goto Reference:=symbol
Selection.ClearContents
Sheets("Stocks").Select
i = i + 1
Set rng = rng.Offset(1, 0)
Loop

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Don't save external data.

You have the advantage of knowing what you want to do. <g

--
Regards,
Tom Ogilvy


"Nick" wrote in message
oups.com...
Okay, thanks. Problem with that is that I've put other data in those
sheets that isn't from the csv file that I want to keep, and
worksheets(symbol).Cells.Clear would delete it. I've found another way
I think:

Dim rng As Range, i As Long
Dim symbol As String
Application.DisplayAlerts = False
Application.ScreenUpdating = False
i = 6
Set rng = Cells(i, 2)
Do While Application.CountA(rng.Resize(1, 15)) < 0
symbol = Cells(i, 2).Value
Sheets(symbol).Select
Application.Goto Reference:=symbol
Selection.ClearContents
Sheets("Stocks").Select
i = i + 1
Set rng = rng.Offset(1, 0)
Loop



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
External Data Warning Message - I have No External Data in wrkbk Cass_makeitfun[_2_] Excel Discussion (Misc queries) 0 May 12th 10 09:02 PM
How do I save external data in Excel? Ankur Bhatnagar Excel Discussion (Misc queries) 0 March 5th 10 11:30 AM
Save Excel without formula drawing from external data skysusan Excel Discussion (Misc queries) 5 October 29th 07 01:19 PM
Cannot save external data into file excel system show not respondi Domino415 Excel Discussion (Misc queries) 0 May 31st 06 09:01 AM
External Data Refresh on save problem RGS Excel Discussion (Misc queries) 0 May 8th 06 01:36 AM


All times are GMT +1. The time now is 05:13 AM.

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"