Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-23-2013, 11:03 AM
BobBridges's Avatar
BobBridges BobBridges is offline Way to search for a string in text file, pull out everything until another string? Windows 7 64bit Way to search for a string in text file, pull out everything until another string? Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default


I'm going to ignore the FileDialog for now. You can incorporate it into your program—it's often very useful—but in order to keep things simple at first, let's assume for this discussion that you already know the full path and filename the file you're going to read. I'm guessing your problem is that you haven't yet defined the object that I called "fso"; that is, the statement "Set fo = fso.OpenTextFile(Fname, 1)" is correct enough, but when VBA gets that far it finds it doesn't know what fso is. It isn't built into VBA as the name of the FileSystemObject; you have to define it.

Depending on whether you want to define it in the References window (I think they call this "early binding"), there are two ways to do it. If you define it in the References—I think it's it more than one of the libraries that have "Scripting" in their titles—then you can just do this:
Code:
  Set fso = New FileSystemObject
Otherwise you have to use the CreateObject function:
Code:
Set fso = CreateObject("Scripting.FileSystemObject")
Either one works; the only difference (I think) is that "early binding" allows you to use the built-in enumerations, eg "ForReading" instead of 1. I do a lot of VBS, too, so I use either one pretty casually.

Once you've got the fso object defined—and you don't have to call it "fso", you can give it any variable name you choose—then your program should proceed normally. I think.
Reply With Quote
  #2  
Old 11-23-2013, 12:10 PM
omahadivision omahadivision is offline Way to search for a string in text file, pull out everything until another string? Windows 7 32bit Way to search for a string in text file, pull out everything until another string? Office 2007
Novice
Way to search for a string in text file, pull out everything until another string?
 
Join Date: Oct 2012
Posts: 28
omahadivision is on a distinguished road
Default

Thanks! It now does everything I want it to! I am very appreciative!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Way to search for a string in text file, pull out everything until another string? Macro to create new word doc and save the file using String found in the document VBNation Word VBA 2 02-08-2013 07:14 AM
Way to search for a string in text file, pull out everything until another string? Find and replace a string of text errtu Word 1 01-31-2013 02:09 PM
Excel Fomula to search for a string and display value from different column zeeshanbutt Excel 1 07-29-2012 12:48 AM
Way to search for a string in text file, pull out everything until another string? Convert numbers to a specific text string francis Excel 1 10-06-2011 01:43 PM
Extract numbers from a text string aleale97 Excel 4 02-10-2011 10:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:22 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft