• WSAndrew77

    WSAndrew77

    @wsandrew77

    Viewing 15 replies - 31 through 45 (of 578 total)
    Author
    Replies
    • in reply to: Bookmark rpt (2003) #952677

      Hi Fred,

      I’ve not heard of anything like that, but you piqued my interest. The following is a rough attempt at most of the functionality you asked for. The collection colBkData contains all the data you’re looking for. For this example, I just dump it out into a new document, but you could of course put it in a table, or otherwise format it.

      Sub GetBookmarkInfo()
      Dim bk As Bookmark
      Dim colBkData As Collection
      Dim col As Collection
      Dim colRefs As Collection
      Dim doc As Document
      Dim strOutput As String
      Dim k As Long
      Dim docReport As Document
      
      Set colBkData = New Collection
      Set doc = ActiveDocument
      doc.Bookmarks.ShowHidden = True
      
      For Each bk In doc.Bookmarks
          Set col = New Collection
          col.Add Key:="name", Item:=bk.Name
          col.Add Key:="page", Item:=bk.Range.Information(wdActiveEndPageNumber)
          col.Add Key:="para-text", Item:=bk.Range.Paragraphs(1).Range.Text
          Set colRefs = FindRefsToBookmark(bk)
          col.Add Key:="refs", Item:=colRefs
          colBkData.Add Item:=col
          Set col = Nothing
      Next bk
      Dim j As Integer
      For k = 1 To colBkData.count
          strOutput = strOutput & _
                 "Bookmark Name: " & colBkData(k)("name") & vbCr & _
                 "Appears on page: " & colBkData(k)("page") & vbCr & _
                 "Surrounding text: " & colBkData(k)("para-text") & vbCr
          If Not colBkData(k)("refs") Is Nothing Then
              For j = 1 To colBkData(k)("refs").count
                  strOutput = strOutput & _
                     "Referenced on page: " & colBkData(k)("refs")(j)("page") & vbCr & _
                      "In the text: " & colBkData(k)("refs")(j)("para-text") & _
                      vbCr & vbCr
              Next j
          End If
      Next k
      Set docReport = Documents.Add
      docReport.Range.InsertAfter strOutput
      End Sub
      '
      Function FindRefsToBookmark(bk As Bookmark) As Collection
      Dim f As Field
      Dim doc As Document
      Set doc = bk.Parent
      Dim colRefData As Collection
      Dim col As Collection
      Set colRefData = New Collection
      
      For Each f In doc.Fields
          Set col = New Collection
          If f.Type = wdFieldRef Then
              If Split(Trim(f.Code))(1) = bk.Name Then
                  f.Select
                  col.Add Key:="page", Item:=Selection.Information(wdActiveEndPageNumber)
                  col.Add Key:="para-text", Item:=Selection.Paragraphs(1).Range.Text
                  colRefData.Add Item:=col
              End If
          End If
          Set col = Nothing
      Next f
      If colRefData.count = 0 Then
          Set FindRefsToBookmark = Nothing
      Else
          Set FindRefsToBookmark = colRefData
      End If
      End Function
      
    • in reply to: how to use NET SEND in VB (VB6) #952235

      I think you might need an API call for that (see the thread at post 81357.

      It can also be done with a somewhat roundabout technique using an available scripting language that does return the output from system calls (see http://www.perl.com/pub/a/2005/05/26/word_control.html%5B/url%5D for an example of such a technique).

    • in reply to: how to use NET SEND in VB (VB6) #952074

      The Shell command does not return the output of the command — it returns the command’s PID.

    • in reply to: Syntax – What Am I Doing Wrong? (Word 2K) #951388

      A simple Case statement would do the trick nicely:

      Select Case sUserName
          Case "User1", "User2", "User3"
              MsgBox "OK" ' Open document
          Case Else
              MsgBox "invalid user" ' Close document
      End Select
      

      Modifying the allowed users is just a matter of editing the first Case.

    • in reply to: The end of .doc format (and .xls, .ppt, etc) (Offi #951092

      That article also answers another question recently asked:

      [indent]


      … which is due when Office 12 hits stores, expected in the second half of next year.


      [/indent]

    • in reply to: The end of .doc format (and .xls, .ppt, etc) (Offi #951091

      Basically, Microsoft is dropping proprietary binary file formats for native XML (with images, content, metadata, etc. all zipped up together). This is very similar to the form used by OpenOffice. (those of you who have OpenOffice, just change the “.sxw” extension to “.zip” on one of your files and then open it to see what I mean).

      More coverage at:
      http://www.washingtonpost.com/wp-dyn/conte…5060101974.html%5B/url%5D

    • in reply to: Calendar Control (VBA/Access/97,2K) #950178

      I’ve never used VBA with Access (I’ve barely used Access), but in Word you can do something like this with the Calendar Control:

      Private Sub UserForm_Activate()
      Me.Calendar1.Value = DateAdd("m", 6, Date)
      End Sub
      
    • in reply to: Unnest a table using VBA (tested in 2002) #950063

      Try this on for size:

      Function PopOuterTable2(tbl As Table) As Boolean
      Dim t As Table
      For Each t In tbl.Parent.Tables
          If tbl.Range.InRange(t.Range) And tbl.NestingLevel > 1 Then
              t.ConvertToText wdSeparateByParagraphs, False
              PopOuterTable2 = True
              Exit Function
          End If
      Next t
      PopOuterTable2 = False
      End Function
      

      Only top-level tables are included in the document’s Tables collection.

    • Try System.PrivateProfileString:

      Sub ReadReg()
      MsgBox System.PrivateProfileString("", _
               "HKEY_CURRENT_USERSoftwareGoogleGmailFlags", _
               "browser") ' --> "firefox.exe"
      End Sub
      

      If you leave the FileName argument blank, VBA looks in the Registry.

    • in reply to: Function v/s Procedure (VBA/All/2000) #949566

      If by “limit user’s visibility”, you mean that you don’t want the procedures to appear in the Macros dialog (Tools->Macro->Macros), you can assign an unused optional parameter:

      Visible from Macros dialog:

      Sub HelloWorld()
      MsgBox "Hello, World!"
      End Sub
      

      Not visible:

      Sub HelloWorld(Optional bNull as Boolean)
      MsgBox "Hello World"
      End Sub
      

      Both can be called identically from other procedures, ie:

      Call HelloWorld
    • in reply to: Word 2003 automatically names your file. (Word 2003) #949561

      Using the full first sentence is how Word 2003 works for me (at least on the two machines I use regularly). The filename you’re saying that Word is using is exactly 8 characters long, which suggests that either Word or Windows is trying to force you to use the old 8.3 filename (8 characters plus 3-character extension) standard.

    • in reply to: Keyboard fails (2003 SP-1) #949551

      I would say it’s almost certainly the touchpad. That happens to me with almost any laptop I use.

      Most laptops have a means of disabling the touchpad, either via a button directly above it, or, more commonly, a Function Key combo (mine’s Fn-F4). Look for an F key (F1-F12) with a picture of a mouse or a mouse with an X through it, or something like that. Fn plus that key should disable the touchpad (pressing it again will toggle it back on).

    • in reply to: Randomizing sentences (N/A) #949325

      There are some subtle parts of this problem that unfortunately I don’t have time to explore right now, but perhaps this will help you or another lounger get to a useful solution.

      The following macro (which uses three supporting functions) makes a list of random numbers between 1 and the number of sentences in the document. Then a new document is created, and the sentences from the original are copied over in that random order.

      The subtleties I was talking about:
      1. Word’s definition of a “sentence” is not always the same as yours.
      2. The trailing paragraph mark at the end of the last sentence in a paragraph is considered part of that sentence, so your paragraph breaks get a bit scrambled.
      3. I know not enough about randomization to know if this is truly “random” enough for your purposes.

      At any rate, it’s an intriguing litte puzzle, and I hope I’ve put the first few pieces in place.

      Sub ShuffleSentencesInDoc()
      Dim doc As Document
      Dim docShuffled As Document
      Dim lRandNum As Long
      Dim k As Long
      Dim lSentenceCount As Long
      Dim vRand() As Variant
      ReDim vRand(0)
      Set doc = ActiveDocument
      lSentenceCount = doc.Sentences.count
      Do While UBound(vRand) < doc.Sentences.count
        lRandNum = GenerateBoundedRandomNumber(1, lSentenceCount)
        If Not IsMember(vRand, lRandNum) Then
          Push vRand, lRandNum
        End If
      Loop
      Set docShuffled = Documents.Add
      For k = 1 To lSentenceCount
          docShuffled.Range.InsertAfter doc.Sentences(vRand(k)).Text
      Next k
      End Sub
      
      Function GenerateBoundedRandomNumber(lLbound As Long, lUbound As Long) As Long
      Randomize
      GenerateBoundedRandomNumber = Int((lUbound - lLbound + 1) * Rnd + lLbound)
      End Function
      
      Function Push(ByRef vArray As Variant, ByVal vItem As Variant)
      ReDim Preserve vArray(UBound(vArray) + 1)
      vArray(UBound(vArray)) = vItem
      End Function
      
      Function IsMember(vArray As Variant, ByVal vItem As Variant)
      Dim v As Variant
      For Each v In vArray
          If v = vItem Then
              IsMember = True
              Exit Function
          End If
      Next v
      IsMember = False
      End Function
      
    • in reply to: Programmatically calling EditUndo (2000/2002/2003) #948857
      ActiveDocument.Undo

      There’s an optional “Times” argument, as well.

    • in reply to: Macro to Remove Duplicate Entries (MS Word 2003) #948824

      Sorry about that. Leave off the 0 in the variant array declarations. I’ve edited the previous post to reflect the change.

    Viewing 15 replies - 31 through 45 (of 578 total)