KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: How to display "Computer Name" in footer?
Topic Summary:
Created On: 06/11/2012 09:57 AM
Status: Post and Reply
Linear : Threading : Single : Branch
 How to display "Computer Name" in footer?   - Roger - 06/11/2012 09:57 AM  
 How to display "Computer Name" in footer?   - Bruce Tjosvold - 06/12/2012 04:02 PM  
 How to display "Computer Name" in footer?   - Bruce Tjosvold - 06/12/2012 04:13 PM  
 How to display "Computer Name" in footer?   - Roger - 06/16/2012 06:58 AM  
 How to display "Computer Name" in footer?   - Larry Allen - 06/21/2012 10:26 AM  
 How to display "Computer Name" in footer?   - R. Wilke - 06/17/2012 05:17 AM  
 How to display   - Roger - 06/17/2012 05:53 AM  
 How to display   - R. Wilke - 06/17/2012 06:30 AM  
 How to display "Computer Name" in footer?   - monkey8 - 06/24/2012 12:36 PM  
 How to display "Computer Name" in footer?   - Roger - 06/25/2012 01:11 PM  
 How to display "Computer Name" in footer?   - monkey8 - 06/25/2012 06:19 PM  
 How to display "Computer Name" in footer?   - Larry Allen - 06/29/2012 11:55 PM  
 How to display "Computer Name" in footer?   - Roger - 06/30/2012 05:21 AM  
Keyword
 06/11/2012 09:57 AM
User is offline View Users Profile Print this message

Author Icon
Roger
Power Member

Posts: 80
Joined: 10/12/2006

I'm using Word 2003 and Windows XP but I'm unable to show the computer name in the footer. I can show the author and path. Someone said there is a way to do this in VBA.

Here is the code I found from 2004.

The UserName is contained in the Author field (should be, anyway) -- so you
can use { DocProperty Author } to insert it in a document. Computer name is
a little trickier -- it's not built in but it is available through the
Environ() collection. You'll need to create your own Document Property for
the purpose. Using VBA it would be something like --

ActiveDocument.CustomDocumentProperties.Add Name:="Computer", _
LinkToContent:=False, _
Type:=msoPropertyTypeString, _
Value:=Environ("ComputerName")

Then in the document, use { DocProperty Computer } to display the value.


Someone also posted this:

'******************** Code Start **************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetComputerName Lib "kernel32" Alias _
    "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function fOSMachineName() As String
'Returns the computername
Dim lngLen As Long, lngX As Long
Dim strCompName As String
    lngLen = 16
    strCompName = String$(lngLen, 0)
    lngX = apiGetComputerName(strCompName, lngLen)
    If lngX <> 0 Then
        fOSMachineName = Left$(strCompName, lngLen)
    Else
        fOSMachineName = ""
    End If
End Function
'******************** Code End **************************



And lastly I found this code (although it is for Word 2007):

The simplest way, although not 100% dependable, is Environ("computername")

 

More complicated, but also more dependable:

 

Private Declare Function GetComputerName Lib "kernel32" _
        Alias "GetComputerNameA" ( _
        ByVal lpBuffer As String, _
        ByRef nSize As Long) As Long

Function ComputerName() As String
  Dim stBuff As String * 255
  Dim lAPIResult As Long
  Dim lBuffLen As Long
  lBuffLen = 255
  lAPIResult = GetComputerName(stBuff, lBuffLen)
  If lBuffLen > 0 Then
    ComputerName = Left(stBuff, lBuffLen)
  End If
End Function

 

You can then use the ComputerName function.





I'm somewhat new at using VBA so I was unable to figure any of these out.

Does anyone know how to do this?

Does anyone know the best way to do this?

I appreciate your help!


Roger



-------------------------

Intel Pent D 930 Dual Core Proc 3.0 GHz, 4MB L2 Cache on a Intel Desktop Board D945PVS 800MHz FSB, 4GB 667MHz DDR2 Non-ECC CL5 DIMM (Kit of 2), 150 GB, 10K RPM, 16 MB Cache - WD Raptor SATA HD, Win XP Pro Ver 2002 SP3 32-bit, Andrea USB Soundpod, Sennheiser ME 3, DNS Pro 11.5 using BestMatch III.



 06/12/2012 04:02 PM
User is offline View Users Profile Print this message


Bruce Tjosvold
Top-Tier Member

Posts: 205
Joined: 10/02/2006

Roger,

 

Here is some code to pop up a window with the value of each system variable.  It may get you closer tpo your goal.

 

Bruce

 

'
    Dim WhatEnviron()
     WhatEnviron = Array ( "allusersprofile" , _
          "appdata" , _
          "avengine" , _
          "clientname" , _
          "commonprogramfiles" , _
          "computername" , _
          "comspec" , _
          "fp_no_host_check" , _
          "homedrive" , _
          "homepath" , _
          "include" , _
          "inoculan" , _
          "lib" , _
          "logonserver" , _
          "number_of_processors" , _
          "os" , _
          "path" , _
          "pathext" , _
          "processor_architecture" , _
          "processor_identifier" , _
          "processor_level" , _
          "processor_revision" , _
          "programfiles" , _
          "sessionname" , _
          "systemdrive" , _
          "systemroot" , _
          "temp" , _
          "tmp" , _
          "userdomain" , _
          "username" , _
          "userprofile" , _
          "vs71comntools" , _
          "wecversionforrosebud.ff0" , _
          "windir" )

     For pgValue = LBound ( WhatEnviron ) To UBound ( WhatEnviron )
          pgTest = MsgBox ( Environ ( WhatEnviron ( pgValue ) ) , vbOkCancel + vbExclamation , WhatEnviron ( pgValue ) )
          Clipboard ( Environ ( WhatEnviron ( pgValue ) ) )
          If pgTest = vbCancel Then Exit For
     Next pgValue

'



-------------------------

1


 


 


 



 06/12/2012 04:13 PM
User is offline View Users Profile Print this message


Bruce Tjosvold
Top-Tier Member

Posts: 205
Joined: 10/02/2006

or, a much simpler script

 

'#Reference {F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}#1.0#0#C:\WINNT\System32\wshom.ocx#Windows Script Host Object Model (Ver 1.0)
' This command uses the Network object of the
' Windows Scripting Host to retrieve the name of the
' computer. It then displays the name in a message
' box.

' Before entering this script, the author had to
' right-click (or press Shift+F10) in the code window
' and add a reference to Windows Script Host Object
' Model. Information on this object model is in the
' Windows Scripting Host Programmer's Guide from
' Microsoft.

Option Explicit
Dim NetworkObject As New IWshNetwork_Class
Dim MyComputerName As String

Sub Main
    MyComputerName = NetworkObject.ComputerName
    MsgBox "This computer's name is " + MyComputerName
End Sub



-------------------------

1


 


 


 



 06/16/2012 06:58 AM
User is offline View Users Profile Print this message

Author Icon
Roger
Power Member

Posts: 80
Joined: 10/12/2006

Bruce,

Thank you for your efforts so far!

However when I ran your "a much simpler script" I got a Compile Error. I attached screen shots of what I am doing in the attached file called "Compile Error.doc"

Please let me know if I am doing anything wrong? I am new to using VBA in dot files.

 

Thanks again,

Roger

 

 



Compile Error.doc
Compile Error.doc  (145 KB)



-------------------------

Intel Pent D 930 Dual Core Proc 3.0 GHz, 4MB L2 Cache on a Intel Desktop Board D945PVS 800MHz FSB, 4GB 667MHz DDR2 Non-ECC CL5 DIMM (Kit of 2), 150 GB, 10K RPM, 16 MB Cache - WD Raptor SATA HD, Win XP Pro Ver 2002 SP3 32-bit, Andrea USB Soundpod, Sennheiser ME 3, DNS Pro 11.5 using BestMatch III.

 06/21/2012 10:26 AM
User is offline View Users Profile Print this message


Larry Allen
Advanced Member

Posts: 181
Joined: 09/04/2007

To make this work, you need to add a "Reference" to the Windows Scripting Host Object Model.

In the Microsoft VB Editor window, go to Tools, then References.  Scroll down the "Available References" to Windows Script Host Object Model and check the box.  Click OK.

It is possible but not likely that your system will not have the Windows Script Host Object Model if that software is not installed.

 



-------------------------

Larry Allen
Softnet Systems, Inc.
http://www.pcspeak.com

 06/17/2012 05:17 AM
User is offline View Users Profile Print this message

Author Icon
R. Wilke
Top-Tier Member

Posts: 4391
Joined: 03/04/2007

Roger,

the "much simpler script" is a sample that comes with the professional version of DNS, and meant to be used as Advanced Scripting from within Dragon, the way it is set up. If you want to use it in VBA, you would need to adopt it accordingly by setting a reference to the library being used, the Windows Scripting Host that is. However, if I were you, I would just use it as is, run it as Advanced Script, and go from there.

Rüdiger



-------------------------

Well, it's past the point where we can make any changes in the code, but we can still make changes to the Easter Egg!



 06/17/2012 05:53 AM
User is offline View Users Profile Print this message

Author Icon
Roger
Power Member

Posts: 80
Joined: 10/12/2006

RĂ¼diger

That would be hard to do since all I want is the computer name to be in the footer of my Word document.

Roger

-------------------------

Intel Pent D 930 Dual Core Proc 3.0 GHz, 4MB L2 Cache on a Intel Desktop Board D945PVS 800MHz FSB, 4GB 667MHz DDR2 Non-ECC CL5 DIMM (Kit of 2), 150 GB, 10K RPM, 16 MB Cache - WD Raptor SATA HD, Win XP Pro Ver 2002 SP3 32-bit, Andrea USB Soundpod, Sennheiser ME 3, DNS Pro 11.5 using BestMatch III.

 06/17/2012 06:30 AM
User is offline View Users Profile Print this message

Author Icon
R. Wilke
Top-Tier Member

Posts: 4391
Joined: 03/04/2007

It is just that the code provided by Bruce isn't meant to be copied and pasted into the VBA editor the way you did it, going by your screenshot. It cannot work this way, being Advanced Scritpting code. I would like to show you how this can be dones, but then I have Word 2010, German edition, and things are likely a little different here from what you have. So you might either go on following the samples you have come up with, but please note than almost any sample needs to be adopted according to the given environment, and just won't work from the start, or you might start from scratch by learning it, which may be a long way to go - but worth it in the end.

However, if the only reason for coming up with VBA was being a last resort in order to compensate for missing functionality in Word by itself, and if, in other words, you aren't using VBA for other reasons also, and haven't really started with it, you may as well go on with Advanced Scripting in Dragon, since you have the Professional version, and anything that can be done in VBA may also be done in Advanced Scripting, aside from both of us talking the same language then (DNS Pro 11.5), and a few more around I would expect to be happy to help also.

RĂ¼diger


-------------------------

Well, it's past the point where we can make any changes in the code, but we can still make changes to the Easter Egg!

 06/24/2012 12:36 PM
User is offline View Users Profile Print this message

Author Icon
monkey8
Top-Tier Member

Posts: 1988
Joined: 01/14/2008

That's a lot of code to get a computer name, there is a built-in command with VBA and Advanced Scripting that will give you the computer name as a string:

Environ$("computername")

You can use the Environ$ method with any of the variables shown in Bruce's list above

e.g. using Advanced Scripting

 SendKeys Environ$("computername")

 SendKeys Environ$("commonprogramfiles")

and like I say you can use the same statement, Environ$("computername"),
to represent any string in VBA.

Lindsay



-------------------------


www.pcbyvoice.com
www.pcbyvoice.co.uk



 06/25/2012 01:11 PM
User is offline View Users Profile Print this message

Author Icon
Roger
Power Member

Posts: 80
Joined: 10/12/2006

Allen and Lindsay,

 

I added/clicked checkbox for Windows Script Host Object Model. I then added Environ$("computername") to the footer. But it did not work.


Footer:
Environ$("computername") -  F:\Roger Intel\Back Up\MS Office 2003\MS Word 2003\Test.dot
Author: Steve Heinze Printed: 6/25/2012 - 10:43 AM Page 1 of 1
 
Please see attached file to see details.

 

Please note: in this instance I do not want to use speech recognition to display the computer name


Thank you  - Roger



Footer.doc
Footer.doc  (91 KB)



-------------------------

Intel Pent D 930 Dual Core Proc 3.0 GHz, 4MB L2 Cache on a Intel Desktop Board D945PVS 800MHz FSB, 4GB 667MHz DDR2 Non-ECC CL5 DIMM (Kit of 2), 150 GB, 10K RPM, 16 MB Cache - WD Raptor SATA HD, Win XP Pro Ver 2002 SP3 32-bit, Andrea USB Soundpod, Sennheiser ME 3, DNS Pro 11.5 using BestMatch III.



 06/25/2012 06:19 PM
User is offline View Users Profile Print this message

Author Icon
monkey8
Top-Tier Member

Posts: 1988
Joined: 01/14/2008

Well I am no expert on Microsoft Word but I doubt you can insert environmental variable directly into the footer.  You can enter your VBA code directly into an event, e.g. the page set up event, probably easier still is just to run a VBA macro just before you save or print the document.  So just add a Word macro, called "footer", with something like the following:

Sub footer()
Dim FooterText As String
FooterText = Environ$("computername") & " Roger had a Little Lamb blah blah blah"
With ActiveDocument.Sections(1)
    .Footers(wdHeaderFooterPrimary).Range.Text = FooterText
End With
End Sub

This will then write the FooterText to all the pages of section 1 of your document.

Lindsay



-------------------------


www.pcbyvoice.com
www.pcbyvoice.co.uk



 06/29/2012 11:55 PM
User is offline View Users Profile Print this message


Larry Allen
Advanced Member

Posts: 181
Joined: 09/04/2007

 

Now I better understand what you want to do.

Add a field at the proper place in the document, using the Word Field choosing DocProperty and then Computer as the Field Property.  I've attached your document modified in this way.






-------------------------

Larry Allen
Softnet Systems, Inc.
http://www.pcspeak.com

 06/30/2012 05:21 AM
User is offline View Users Profile Print this message

Author Icon
Roger
Power Member

Posts: 80
Joined: 10/12/2006

Larry Allen,

THANK YOU, it works beautifully, it's exactly what I wanted!!!!!

Hoooraaayyy!

Roger



-------------------------

Intel Pent D 930 Dual Core Proc 3.0 GHz, 4MB L2 Cache on a Intel Desktop Board D945PVS 800MHz FSB, 4GB 667MHz DDR2 Non-ECC CL5 DIMM (Kit of 2), 150 GB, 10K RPM, 16 MB Cache - WD Raptor SATA HD, Win XP Pro Ver 2002 SP3 32-bit, Andrea USB Soundpod, Sennheiser ME 3, DNS Pro 11.5 using BestMatch III.



Statistics
27371 users are registered to the KnowBrainer Speech Recognition forum.
There are currently 5 users logged in.
The most users ever online was 2028 on 04/05/2013 at 07:36 PM.
There are currently 76 guests browsing this forum, which makes a total of 81 users using this forum.

FuseTalk Standard Edition v4.0 - © 1999-2013 FuseTalk™ Inc. All rights reserved.