PDA

View Full Version : Solved: Get text from header



gibbo1715
11-03-2005, 02:17 AM
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

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


Cheers

Gibbo

gibbo1715
11-03-2005, 02:52 AM
Cancel the second part, can use the vb method

Kill (StrFile)


Gibbo

Marcster
11-03-2005, 03:04 AM
Something along the lines of:

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

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.

gibbo1715
11-03-2005, 03:39 AM
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

TonyJollans
11-03-2005, 03:45 AM
Viewing and selecting are far too much.

Use something like ...

ActiveDocument.Sections(1).Headers(1).Range.Tables(1).etc....

gibbo1715
11-03-2005, 03:48 AM
Thanks Tony,

Gibbo

Killian
11-03-2005, 03:59 AM
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 eventualitiesSub 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

gibbo1715
11-03-2005, 04:49 AM
thankyou all

Solved again

Gibbo

MOS MASTER
11-03-2005, 03:42 PM
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