Can some one help me with this code plz

Reply

Join Date: Jul 2006
Posts: 10
Reputation: Maria_19 is an unknown quantity at this point 
Solved Threads: 0
Maria_19 Maria_19 is offline Offline
Newbie Poster

Can some one help me with this code plz

 
0
  #1
Jul 25th, 2006
Hey guyz
I got this search macro from the web for my excel project but as Iam a beginner i really dont know how to modify it. I need to use this search code to identify and retrieve documents for that its going to scan through a especified location. I don know how to especify the location out side excel can some one plz help
Search Macro

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Public Sub Test()
  2. Dim SR As Integer
  3. Dim ER As Integer
  4. Dim SC As Integer
  5. Dim EC As Integer
  6. Dim RowVar As Integer
  7. Dim ColVar As Integer
  8. Dim found As Boolean
  9.  
  10. 'Change the indexes for your own Row range from 1 to 65536
  11. SR = 1
  12. ER = 20
  13. 'Change the indexes for your own Column range from 1 to 256 - in English from "A" to "IV"
  14. SC = 1
  15. EC = 10
  16. found = False
  17. For RowVar = SR To ER
  18. For ColVar = SC To EC
  19. If Not found Then 'This ensures that you stop at the first occurrence
  20. If Cells(RowVar, ColVar).Formula = "Angstrom" Then 'This is where your search text goes
  21. Cells(RowVar, ColVar).Select
  22. found = True
  23. End If
  24. End If
  25. Next
  26. Next
  27. End Sub
  28. Set xlApp = Nothing
  29. End Sub
Last edited by Comatose; Jul 25th, 2006 at 7:51 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 85
Reputation: williamrojas78 is an unknown quantity at this point 
Solved Threads: 4
williamrojas78's Avatar
williamrojas78 williamrojas78 is offline Offline
Junior Poster in Training

Re: Can some one help me with this code plz

 
0
  #2
Jul 25th, 2006
Hi

You have to set the workbook you want to search, and then set the range. I guess the range is always going to be the same.

Somthing like this will open the workbook and set the sheet1 as the sheet you will working on :

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. Dim oWB As Workbook
  3. Dim oSheet As Worksheet
  4.  
  5. Workbooks.Open Filename:="C:\test.xls"
  6. Set oWB = ActiveWorkbook
  7.  
  8. Set oSheet = oWB.Sheets("Sheet1")
  9. oSheet.Range("a1:a21").Select

After that do the search in the specified range as you did before.

Hope it helps
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Can some one help me with this code plz

 
0
  #3
Jul 25th, 2006
I should merge this and your other thread, since they are about the same topic.... but for now, I'll leave them be. The code you posted only searches through the grid of the excel document, and (as far as I can tell) never onces looks at any kind of filename. I can code a sub/function to do what you want.... the problem we are facing is that this will be done strictly in VB6 Code. Yes, there is a difference between VB and VBA, but it's not extreme... and the problem is that I don't know how much (if any) of the commands/keywords that vb6 has are not in VBA. I know that vb6 has some additional commands, and certainly added power that you simply can not harness with VBA, but I'm not sure (since I don't use office) if the code will work 100% as is.... so try this sub, and let's see where we need to modify.... baby steps.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Public Sub GetDocumentStr(PartOfFileName, FolderToSearch)
  2. If Right(FolderToSearch, 1) <> "*" Then
  3. If Right(FolderToSearch, 1) <> "\" Then FolderToSearch = FolderToSearch & "\"
  4. FolderToSearch = FolderToSearch & "*.*"
  5. End If
  6.  
  7. TFname = Dir(FolderToSearch)
  8. Do While TFname <> ""
  9. If InStr(1, TFname, PartOfFileName) <> 0 Then
  10. Exit Do
  11. End If
  12. TFname = Dir
  13. Loop
  14.  
  15. If TFname = "" Then
  16. MsgBox "None Found"
  17. Else
  18. MsgBox TFname
  19. End If
  20. End Sub

Now, that Sub only does part of what you want.... it searches a folder you give it, for a part of a filename that you specify, and then pops up a box telling you the name (or none if that text is not found in a file name)..... The reason I built it this way, is because I have no idea which cell you plan to use to get the file name from. We can modify this little by little until we get it where you need it to be, but for now, let's make sure this works, and post again with any changes you need.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 10
Reputation: Maria_19 is an unknown quantity at this point 
Solved Threads: 0
Maria_19 Maria_19 is offline Offline
Newbie Poster

Re: Can some one help me with this code plz

 
0
  #4
Jul 26th, 2006
Thanx william
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 10
Reputation: Maria_19 is an unknown quantity at this point 
Solved Threads: 0
Maria_19 Maria_19 is offline Offline
Newbie Poster

Re: Can some one help me with this code plz

 
0
  #5
Jul 26th, 2006
Thanx Comatoes I really appriciate the fact that you took time out to help me.
You already know about my project The idea is to have a macro do two things basically search and retrieve. what i wanned it to do was search the directory as in out side Excel. I got this code: It pretty much does what i want but i need your help in some modifications plzzz.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Sub DirLoop()
  2. Dim MyFile As String, Sep As String, filename1 As String
  3. filename1 = "H:\2006\Course Description\AIX 5L"
  4. ' Sets up the variable "MyFile" to be each file in the directory
  5. ' This example looks for all the files that have an .xls extension.
  6. ' This can be changed to whatever extension is needed. Also, this
  7. ' macro searches the current directory. This can be changed to any
  8. ' directory.
  9. ' Test for Windows or Macintosh platform. Make the directory request.
  10. Sep = Application.PathSeparator
  11. If Sep = "\" Then
  12. ' Windows platform search syntax.
  13. MyFile = Dir(filename1 & Sep & "*.doc")
  14. Else
  15. ' Macintosh platform search syntax.
  16. ' MyFile = Dir("", MacID("XLS5"))
  17. End If
  18. ' Starts the loop, which will continue until there are no more files
  19. ' found.
  20. Do While MyFile <> ""
  21. ' Displays a message box with the name of the file. This can be
  22. ' changed to any procedure that would be needed to run on every
  23. ' file in the directory such as opening each file.
  24. MsgBox filename1 & Sep & MyFile
  25. MyFile = Dir()
  26. Loop
  27. End Sub
Now the problem with this code is that it goes in the specified path and starts poping up names of all the files in msg boxs. What I need is it to jus search the specific file name and retrieve the file as in "Open file.doc " not display the names only. Do you think u can help plzzzz! I believe if i merg the two codes (urs and mine) I should be able to get what m lukin for but i am a beginner so Iam not so confident about my work
Last edited by Comatose; Jul 30th, 2006 at 12:14 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Can some one help me with this code plz

 
0
  #6
Jul 26th, 2006
For what you want to do, your code is way to static (doesn't change). You want to search a directory, by the info in a cell of an excel document...... you need to be able to change which directory you are searching, and what name of the document you need..... when I get home from work, I'll make it open the document in excel.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 10
Reputation: Maria_19 is an unknown quantity at this point 
Solved Threads: 0
Maria_19 Maria_19 is offline Offline
Newbie Poster

Re: Can some one help me with this code plz

 
0
  #7
Jul 29th, 2006
I tried ur search macro it worked! I specified cells to pick up the search string it works fine Thanx alot
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Can some one help me with this code plz

 
0
  #8
Jul 29th, 2006
So, It is all working correctly?
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 10
Reputation: Maria_19 is an unknown quantity at this point 
Solved Threads: 0
Maria_19 Maria_19 is offline Offline
Newbie Poster

Re: Can some one help me with this code plz

 
0
  #9
Jul 29th, 2006
No Iwont say that I dont need any more help NOWAY! but for now since the search code is working m trying to work on how to make it open the .doc file and insert it at the end of a word document proposal. Do u think you can help me out with it?? Ican forward u the search code with the modifications i made if its required?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Can some one help me with this code plz

 
0
  #10
Jul 30th, 2006
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC