Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    For ... Next loop (WinNT4/Word97)

    <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23> I'm not having a good week so far!

    Would someone tell me where I'm going wrong here?! I've tried all sorts of combinations but the example for-next loop in the help file is too different from this for me to be able to track down the problem! All I'm trying to do is display a msgbox containing all custom document property names and their values!

    Dim props As String, i
    props = ""
    For Each i In ActiveDocument.CustomDocumentProperties
    props = props + ActiveDocument.CustomDocumentProperties(i).Name + " = " + ActiveDocument.CustomDocumentProperties(i).Value + Chr(13)
    Next i
    MsgBox props


    Many thanks in advance!
    Beryl M


  2. #2
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: For ... Next loop (WinNT4/Word97)

    Thanks, Alan, but no - it says 'invalid procedure or call argument'. <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15>

    By the way, how did you get the code lines to sit away from the left margin without using 'pre' tags (which would put the text in courier)?
    Beryl M


  3. #3
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: For ... Next loop (WinNT4/Word97)

    Maybe this will work for you:

    Dim props As String, i As DocumentProperty
    props = ""

    For Each i In ActiveDocument.CustomDocumentProperties
    props = props & i.Name & " = " & i.Value & Chr(13)
    Next i

    MsgBox props

    Alan

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: For ... Next loop (WinNT4/Word97)

    i is already a custom document property, so trying to use ActiveDocument.CustomDocumentProperties(i) is a contamination.

    Either use

    Dim props As String, i As DocumentProperty
    For Each i In ActiveDocument.CustomDocumentProperties
    props = props & i.Name & " = " & i.Value + Chr(13)
    Next i

    or

    Dim props As String, i As Long
    For i = 1 To ActiveDocument.CustomDocumentProperties.Count
    props = props & ActiveDocument.CustomDocumentProperties(i).Name & " = " & _
    ActiveDocument.CustomDocumentProperties(i).Value + Chr(13)
    Next i

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: For ... Next loop (WinNT4/Word97)

    Alan, you cheated! I just looked back at your post and realised you'd changed your code!!

    Now it looks like I'm saying that code doesn't work (it does, by the way) whereas it was the original code as follows that didn't:

    Dim props As String, i As DocumentProperty
    props = ""

    For Each i In ActiveDocument.CustomDocumentProperties
    props = props & ActiveDocument.CustomDocumentProperties(i).Name & " = " & _
    ActiveDocument.CustomDocumentProperties(i).Value & Chr(13)
    Next i

    MsgBox props

    Please don't change posts once they've been answered (especially ones like these!) - it makes a complete nonsense of the thread!!!!
    Beryl M


  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: For ... Next loop (WinNT4/Word97)

    I always use <!t>[tab]<!/t> tags to indent code. If I want to post a medium-length piece of code, I paste it into Word, then run the macro from <post#=346967>post 346967</post#>.

    (If I want to post a long piece of code, I attach it in a text file)

  7. #7
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: For ... Next loop (WinNT4/Word97)

    Thanks, Hans! That works!
    Beryl M


  8. #8
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: For ... Next loop (WinNT4/Word97)

    Ah - I hadn't discovered the 'tab' tag. I'll have to remember that.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Beryl M


  9. #9
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: For ... Next loop (WinNT4/Word97)

    <hr>Please don't change posts once they've been answered (especially ones like these!) - it makes a complete nonsense of the thread!!!!<hr>

    And please don't be so trigger happy when shooting from the hip. I made the alteration immediately after posting, having noticed my mistake <big>AND BEFORE</big> your reply had appeared. Now let's pop our six shooters away, while we still have one foot left. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    Alan

  10. #10
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: For ... Next loop (WinNT4/Word97)

    Well, in that case we both must have been pretty quick off the mark, because I read your post, copied the code, pasted it in my VBA window, ran it, made a note of the error, typed my reply and posted it, and the code in your post was still the original then!

    However, I apologise for being 'trigger happy' if that's the case!

    Mind you, it is considered correct netiquette to make a note on your post to say if you've changed it, because the recipient (whose post you answered - me in this case) will have received it in its original form, but *won't* have been told that it's been changed.

    Anyway, cheers for the code, which does now work!

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Beryl M


  11. #11
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: For ... Next loop (WinNT4/Word97)

    No problem. I didn't anticipate you'd be so quick off the mark. I'll remember that trigger finger in future. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Alan

  12. #12
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: For ... Next loop (WinNT4/Word97)

    To be fair, it's not so much that I was fast as, since I get notified by email of replies, I knew as soon as you posted, but as I mentioned above these notifications don't tell us when the post is edited!

    It's by no means the first time I've replied to a post that's changed without me knowing <img src=/S/sad.gif border=0 alt=sad width=15 height=15> and only found out it's changed much later!

    <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15> it seems even the Lounge isn't perfect (although much closer than any other forum I've come across!).
    Beryl M


  13. #13
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: For ... Next loop (WinNT4/Word97)

    So, please, what is the end-result of all this? Is it "Un-DIMensioned variables can cause problems"?

  14. #14
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: For ... Next loop (WinNT4/Word97)

    Sorry, that one went past a bit fast for me? <img src=/S/confused.gif border=0 alt=confused width=15 height=20>
    Beryl M


  15. #15
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: For ... Next loop (WinNT4/Word97)

    <post#= 481934 >post 481934 </post#> suggested declaring the variable "i" with a Type (DocumentProperty or Long), and in the ensuing discussion I didn't read that doing so had actually worked for you.

    My interest stems not from the task you were trying to achieve but from a nearly life-long interest in programming standards. In so many different languages I've been tripped up because I did not declare or initialize my variables.

    P.S. I'm replying rather than editing because I can count, and you still have 4 bullets left (love ya!)

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •