Consulting

Results 1 to 9 of 9

Thread: Solved: Get text from header

  1. #1
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location

    Solved: Get text from header

    All

    I have two questions that will enable me to finish my project

    1. I have some text in a table in my header in the format 11/111111111111

    How can i select this via code.

    2. Need to Delete a document ( I am moving a document to a new location so need to delete the previous copy from the old location) Im ok with all the rest of the code, just need the delete command

    Tried the following but didnt work as I expected really

    [VBA]Sub Macro1()
    Dim StrFile As String
    StrFile = "W:\Gatekeeper\Test.Doc"
    Document.Delete (StrFile)
    End Sub
    [/VBA]

    Cheers

    Gibbo

  2. #2
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    Cancel the second part, can use the vb method
    [VBA]
    Kill (StrFile)
    [/VBA]

    Gibbo

  3. #3
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Something along the lines of:
    [VBA]
    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
    ActivePane.View.Type = wdOutlineView Then
    ActiveWindow.ActivePane.View.Type = wdPrintView
    End If
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

    <SELECT THE TEXT HERE> <using 'Selection.'>

    Selection.Copy
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    [/VBA]
    This isn't quite finished, the <SELECT TEXT HERE> bit requires some code,
    but hopefully points you in the right direction.
    Hope this helps,

    Marcster.

  4. #4
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    Thanks Marcster, works fine for me

    One more question before i mark this as solved how do i get the name of the document returned without the .doc on the end like you get with ActiveDocument.Name

    Cheers

    Gibbo

  5. #5
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Viewing and selecting are far too much.

    Use something like ...

    ActiveDocument.Sections(1).Headers(1).Range.Tables(1).etc....
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  6. #6
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    Thanks Tony,

    Gibbo

  7. #7
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Regarding the document name
    I suppose you have to strip the extension off .Name
    Bearing in mind we could be dealing with .docx soon, and also users can mess with names and extensions without affecting the file, I would use a function that caters for those eventualities[VBA]Sub test()
    Dim strDocName As String
    strDocName = GetDocName(ActiveDocument)
    End Sub

    Function GetDocName(docDocument As Document) As String
    Dim DotPos As Long
    DotPos = InStr(1, docDocument.Name, ".")
    If DotPos > 0 Then
    GetDocName = Left(docDocument.Name, DotPos - 1)
    Else
    GetDocName = docDocument.Name
    End If
    End Function[/VBA]
    K :-)

  8. #8
    VBAX Expert
    Joined
    Jan 2005
    Posts
    574
    Location
    thankyou all

    Solved again

    Gibbo

  9. #9
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by gibbo1715
    Thanks Marcster, works fine for me

    One more question before i mark this as solved how do i get the name of the document returned without the .doc on the end like you get with ActiveDocument.Name

    Cheers

    Gibbo
    To complement Killians great answer, some more interesting methods to return a filename from the KB: http://vbaexpress.com/kb/getarticle.php?kb_id=767
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

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