473,383 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

For each... next help needed

21
For Each variant In ThisDocument
[statements]
Next variant

for the above code i need VBA to scan all of the document and find each " ' " but "thisdocument" doesn't work neither does "wholestory" anyone got any suggestions?

cheers Blacbox
Oct 29 '06 #1
14 1966
willakawill
1,646 1GB
For Each variant In ThisDocument
[statements]
Next variant

for the above code i need VBA to scan all of the document and find each " ' " but "thisdocument" doesn't work neither does "wholestory" anyone got any suggestions?

cheers Blacbox
Hi, perhaps you could use InStr(ThisDocument, " ' ")
Oct 29 '06 #2
Killer42
8,435 Expert 8TB
Hi, perhaps you could use InStr(ThisDocument, " ' ")
Given the nature of the For Each... statement, I think that would be Instr(variant, " ' ").
Oct 29 '06 #3
Blckbx
21
thanks but when i use

x = InStr(1, ThisDocument, "'")

firstly if i leave out the 1 it takes "this document" as the start and secondly instr returns a value of 0 why? there definitely are ' in the text.

any suggestions? cheeers

blackbox
Oct 30 '06 #4
Killer42
8,435 Expert 8TB
Could you paste in here the whole section of code?
Oct 30 '06 #5
Blckbx
21
x = 1
With Selection
.GoTo what:=wdGoToPage
.MoveRight unit:=wdCharacter, Count:=NumCharsBefore
.TypeText Text:=Chr(146)
x = InStr(1, ThisDocument, "'")
.MoveRight unit:=wdCharacter, Count:=x
UserForm1.ListBox3.AddItem (Selection.Text)
Do
x = InStr(x, ThisDocument, "'")
.MoveRight unit:=wdCharacter, Count:=x
UserForm1.ListBox3.AddItem (Selection.Text)
Loop Until n = NumCharsBefore
End With

that's what i've got so far straight off the page
Oct 30 '06 #6
Blckbx
21
to be honest i might just elave it as i managed to re-write the code so it works using if then statements, roughly the same lenght just takes abit longer. the real reason i came on here again is a question about variants, if i want a to paste the entire contents of a variant how would i go about doing that?
Oct 30 '06 #7
Killer42
8,435 Expert 8TB
to be honest i might just elave it as i managed to re-write the code so it works using if then statements, roughly the same lenght just takes abit longer. the real reason i came on here again is a question about variants, if i want a to paste the entire contents of a variant how would i go about doing that?
Getting outside my area of expertise there, but I imagine it would depend on the contents (type) of the variant and where you want to paste it.
Oct 30 '06 #8
Killer42
8,435 Expert 8TB
Maybe it's just me, but when I run a macro and check, ThisDocument refers to the Normal.Dot template. Perhaps you have the same problem?
Oct 30 '06 #9
Blckbx
21
have sorted the variant problem just used do...loop

when i refer to a thisdocument it refers to the actual document as the code is written in the project rather than the normal.

i could go on asking problems all night if you want to stay and help?
Oct 30 '06 #10
Killer42
8,435 Expert 8TB
have sorted the variant problem just used do...loop

when i refer to a thisdocument it refers to the actual document as the code is written in the project rather than the normal.

i could go on asking problems all night if you want to stay and help?
I was actually editing my earlier reply, but TheScripts told me I had run out of time (apparently you only have 5 minutes after posting to edit). Here's what I was about to post...


Perhaps ActiveDocument or ActiveDocument.Content would work? After interrupting macro execution I went to the immediate window and printed some things. Here's the result.
Expand|Select|Wrap|Line Numbers
  1. ? thisdocument
  2. Normal.dot
  3. ? activedocument
  4. Document1
  5. ? activedocument.Content
  6. Ds gkjsdklhgsdlgj dgj haksl haslkj fglaksf akslfasfsadf
This garbage string is the text I had typed into the test document, of course.

So, it looks as though your code is (or was) actually scanning the name of either the document or the template, depending on your setup.
Oct 30 '06 #11
Killer42
8,435 Expert 8TB
Oh, and sorry, I don't have time to stick around. It's not night here, and I'm at work. :)
Oct 30 '06 #12
Blckbx
21
instr still returns a value of "0" it's probably something to do with the text i'm using.

also do you happen to know / suggest code for counting the frequency of each letter in a document? i have managed to find some but it's rather long, if not could you tell me how to only find and replace in a certain part of the document?
Oct 30 '06 #13
Killer42
8,435 Expert 8TB
instr still returns a value of "0" it's probably something to do with the text i'm using.

also do you happen to know / suggest code for counting the frequency of each letter in a document? i have managed to find some but it's rather long, if not could you tell me how to only find and replace in a certain part of the document?
I'm really curious about the Instr - could you paste the latest version of the statement here? It's usually pointless when people just describe code, as it's the fine details which make the difference, and they're always left out.

As for counting a letter, I know the Find function can do that - to demonstrate, do a Find in Word, check the "Highlight all items found..." checkbox, and hit the Find All button. As well as highlighting (selecting) all of the occurrences found, it tells you the count in the dialogue box. So it should be possible to retrieve the same information in code. I don't know how though, sorry. (Be careful afterward, as the highlighted items are in fact selected, just as though you dragged over them.)

As for replacing in a certain section, I expect it's just a matter of selecting the text then using the usual replace function/method, but on the Selection object. There are bound to be others in the forum who can provide better detail on this.
Oct 30 '06 #14
Blckbx
21
have managed to get it all to work, i made a silly mistake with the instr, it wouldnt let me search for chr(146) and i wouldn't let me use ' either so i used " ' " (without the spaces) so then it searched for exactly what i aske dit to, so used a var insteaed. small question: when searchnig through a certain part of a document it says it's finished and would i like to search the rest? the answer is always no but unfortunately i have to tell it this 104 times, is there anyway of automating it?

cheers Blackbox
Nov 1 '06 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Kiteman - Canada | last post by:
I have the following: a form called Form1 an image called Image1 twelve lines that have been drawn and superimposed on the image I wish to have a command button that will toggle the lines on...
80
by: | last post by:
Is there a performance difference between this: \\\ Dim i As Integer For i = 0 to myObject.Controls.Count - 1 myObject.Controls(i) = ... Next /// and this:
2
by: Patrik | last post by:
Hi, I cannot find the right way to write this code. I keep getting the error : Next without For Here's my code. For Each Choix In RapInd_Code.ItemsSelected S6 =...
2
by: crjunk | last post by:
I'm trying to write a piece of code that will programatically save a record automatically without me having to add a new ' Row.Item("ADD1") = txtAdd1.Text.Trim.ToUpper ' type command each time I...
3
by: Andrew J. Marshall | last post by:
It was SO easy in VB6. Add a few methods, set a few funky properties and *BAM*, type-safe collection class that supports the For Each...Next syntax. I've been trying to do this in VB.NET with...
8
by: Belee | last post by:
I have the following code and it is not passing through the Next statement: Private Function IsItemAlreadyAdded() As Boolean Dim drMyRow As DataRow With Me For Each drMyRow In...
6
by: Michael D. Ober | last post by:
In VB 6, the loop iterator v in the following code must be a variant. dim v as variant dim c as new collection for each v in collection ... next v What is the general translation in VB 7.1...
7
by: Michael Kellogg | last post by:
I created a custom collection based on System.Collections.Specialized.NameObjectCollectionBase. I also implemented two version of the "Item" property and coded them both as Default properties. ...
17
by: The Frog | last post by:
Hello everyone, I am working on an application that can build database objects in MS Access from text files. I suppose you could call it a backup and restore type routine. Accessing the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.