Try the following:
Public Declare Function GetComputerName Lib "kernel32" _
Alias "GetComputerNameA" ( _
ByVal lpBuffer As String, _
nSize As Long) As Long
Sub CompNameToHeaderFooter()
Dim CompName As String
Dim L As Long
CompName = String$(260, vbNullChar)
L = Len(CompName)
GetComputerName CompName, L
CompName = Left(CompName, L)
ActiveSheet.PageSetup.CenterHeader = CompName
ActiveSheet.PageSetup.CenterFooter = CompName
End Sub
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
"Akash" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Feb 22, 11:15 am, dkinn <d...@discussions.microsoft.com> wrote:
>> Hi Eric
>>
>> You didn't mention what version of Excel you were using but here is a 32
>> bit
>> version that works under most recent version, I haven't tried it under
>> 2007
>> or Vista but it works under XP
>>
>> Open a standard module and paste the following code
>>
>> Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA"
>> (ByVal lpBuffer As String, nSize As Long) As Long
>>
>> Sub Get_Computer_Name_Ex()
>> Dim Comp_Name_B As String * 25
>> 'this function seems to work differntly than most, it doesn't return
>> the
>> number of char's placed in the buffer
>> Ret = GetComputerName(Comp_Name_B, Len(Comp_Name_B))
>> 'but the string is always ended with a null terminated string so we
>> can
>> use the Chr(0) function to find the end
>> Comp_Name = Left(Comp_Name_B, InStr(Comp_Name_B, Chr(0)))
>> 'and return only the computer name
>> MsgBox Comp_Name
>> End Sub
>>
>> hope this helps
>>
>> David
>>
>> "Eric" wrote:
>> > Hello,
>>
>> > I would like my macro to check the name of the computer before running.
>> > How can I retrieve the computer name value through a macro?
>>
>> > Thank you.
>>
>> > Eric
>
> its not working Eric, I want to get it print on my Excel Header &
> Footer
>
> hws would i do the same
>