Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro based Import Data Inserts Cells, I want Replace


I recorded a macro to import data from a text file. When I record i
interactively, I replace data, but when I integrate this script into
macro it always shoves old data over, which screws up my cel
references in other formulas. How can I modify this code to replac
data instead?

Sheets(HOTPAGE).Select
Cells(8, 1).Select
' Selection.Delete Shift:=xlUp
Selection.Clear
With Sheets(HOTPAGE).QueryTables.Add(Connection:= _
"TEXT;" & HOTSAUCE, Destination:=Sheets(HOTPAGE).Cells(8, 1))
.FieldNames = True
.RowNumbers = False
' .FillAdjacentFormulas = False
.FillAdjacentFormulas = True
.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 = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
' .TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False

Thanks a bunch,

Bram Weisma

--
bramweisma
-----------------------------------------------------------------------
bramweisman's Profile: http://www.excelforum.com/member.php...nfo&userid=174
View this thread: http://www.excelforum.com/showthread.php?threadid=38577

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Macro based Import Data Inserts Cells, I want Replace

It looks like your problem is that you are calling the ADD method for the
QueryTable repeatedly. You probably want to call the Refresh method of the
QueryTable to update it after it has been created. Try the following:

Add this line to your create statement:

..Name = HOTSAUCE

Where HOTSAUCE is a valid name for the QueryTable.

In the code that does the refresh simply put this:

ActiveSheet.QueryTables(HOTSAUCE).Refresh

I think this will work.

The only other thing that could have an impact is the RefreshStyle proprty.
Look it up in Excel help and it will tell you what the options do.

Hope this helps.

By the way, this is new to me, but it looks useful for linking to SQL
Server, which is what I do on a daily basis.

Thanks for opening my eyes to something new.
--
Happy Coding,

Scott


"bramweisman" wrote:


I recorded a macro to import data from a text file. When I record it
interactively, I replace data, but when I integrate this script into a
macro it always shoves old data over, which screws up my cell
references in other formulas. How can I modify this code to replace
data instead?

Sheets(HOTPAGE).Select
Cells(8, 1).Select
' Selection.Delete Shift:=xlUp
Selection.Clear
With Sheets(HOTPAGE).QueryTables.Add(Connection:= _
"TEXT;" & HOTSAUCE, Destination:=Sheets(HOTPAGE).Cells(8, 1))
.FieldNames = True
.RowNumbers = False
' .FillAdjacentFormulas = False
.FillAdjacentFormulas = True
.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 = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
' .TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False

Thanks a bunch,

Bram Weisman


--
bramweisman
------------------------------------------------------------------------
bramweisman's Profile: http://www.excelforum.com/member.php...fo&userid=1746
View this thread: http://www.excelforum.com/showthread...hreadid=385776


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 replace comma with point in import data Gepetto Excel Worksheet Functions 2 November 21st 09 07:54 PM
Macro to import & update rows in spreadsheet based on Ref ID. Harry Seymour[_2_] Excel Discussion (Misc queries) 0 June 9th 08 04:05 PM
Find and Replace based on neighboring cells? djc Excel Discussion (Misc queries) 4 December 5th 07 03:18 PM
How to import data based on a variable kjp55 Excel Worksheet Functions 8 June 9th 06 12:34 AM
Macro that inserts lines Esrei Excel Discussion (Misc queries) 1 May 9th 05 01:50 PM


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