Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 3rd, 2003, 06:50 PM
crazy_bit crazy_bit is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 1 crazy_bit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question vb in excel, table entries

Can vb extract data from a file in c:/ and put it in the entries of column A?.
If the answer is yes, how the vb code look ?.
I'm very novice in it, but I know some of programation, c++ and pascal.

joe.

Reply With Quote
  #2  
Old September 5th, 2003, 04:25 AM
Silian's Avatar
Silian Silian is offline
Gogga
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 198 Silian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
I'm assuming that you're talking abt a text file.

This can be done in one of two ways: File handling (very much like you'll do it pascal)
Code:
Sub Macro1()
Dim oFso
Dim oFile
Dim oText
Dim iRow
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oFile = oFso.GetFile("C:\test.txt")
Set oText = oFile.OpenAsTextStream(1)
iRow = 1
    s = oText.readline
    While oText.AtEndOfStream <> True
        Cells(iRow, 1).Value = s
        iRow = iRow + 1
        s = oText.readline
    Wend
oText.Close
Set oText = Nothing
Set oFile = Nothing
Set oFso = Nothing
    
End Sub


or you can open the text file as an excel file, and copy and paste the data into column A (I recorded this macro, 2 get the code)
Code:
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 2003/09/04
    ChDir "C:\"
    Workbooks.OpenText Filename:="C:\Test.txt", Origin:=xlWindows, StartRow:= _
        1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
        ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
        , Space:=False, Other:=False, FieldInfo:=Array(1, 1)
    Columns("A:A").Select
    Selection.Copy
    Windows("Book2").Activate
    ActiveSheet.Paste
End Sub

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > vb in excel, table entries


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT