Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Computer Name with VBA
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Computer Name with VBA
environ("computername")
-- Gary "Eric" wrote in message ... 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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Computer Name with VBA
in case you need some code to show usage, maybe something like this:
Sub get_name() Dim computername As String computername = Environ("computername") MsgBox computername End Sub -- Gary "Eric" wrote in message ... 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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Computer Name with VBA
in case you need some code to show usage, maybe something like this:
Sub get_name() Dim computername As String computername = Environ("computername") MsgBox computername End Sub -- Gary "Eric" wrote in message ... 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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Computer Name with VBA
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 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Computer Name with VBA
On Feb 22, 11:15 am, dkinn 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 |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Computer Name with VBA
change the sheet name and range to your needs: just paste this code in a blank
workbbok and it should work, though. Sub print_name() Dim ws As Worksheet Dim computername As String computername = Environ("computername") Application.ScreenUpdating = False Set ws = Worksheets("sheet1") With ws.PageSetup .PrintTitleRows = "$1:$1" .Orientation = xlPortrait .CenterHeader = "&B&12" & computername .PrintGridlines = True .Zoom = 100 .RightMargin = Application.InchesToPoints(0.4) .LeftMargin = Application.InchesToPoints(0.4) .TopMargin = Application.InchesToPoints(0.75) .HeaderMargin = Application.InchesToPoints(0.25) .BottomMargin = Application.InchesToPoints(0.5) .RightFooter = "Page " & "&P" & " of " & "&N" .RightHeader = "&B&12 " & Date .PrintArea = "A1:G10" .CenterFooter = "" .FooterMargin = Application.InchesToPoints(0.3) .CenterHorizontally = True End With ws.PrintPreview Application.ScreenUpdating = True End Sub -- Gary "Akash" wrote in message oups.com... On Feb 22, 11:15 am, dkinn 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 |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Computer Name with VBA
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" wrote in message oups.com... On Feb 22, 11:15 am, dkinn 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 |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
Computer Name with VBA
It works, thank you.
Eric "Gary Keramidas" <GKeramidasATmsn.com wrote in message ... in case you need some code to show usage, maybe something like this: Sub get_name() Dim computername As String computername = Environ("computername") MsgBox computername End Sub -- Gary "Eric" wrote in message ... 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 |
#10
Posted to microsoft.public.excel.programming
|
|||
|
|||
Computer Name with VBA
Very nice. Thank you.
Eric "Gary Keramidas" <GKeramidasATmsn.com wrote in message ... change the sheet name and range to your needs: just paste this code in a blank workbbok and it should work, though. Sub print_name() Dim ws As Worksheet Dim computername As String computername = Environ("computername") Application.ScreenUpdating = False Set ws = Worksheets("sheet1") With ws.PageSetup .PrintTitleRows = "$1:$1" .Orientation = xlPortrait .CenterHeader = "&B&12" & computername .PrintGridlines = True .Zoom = 100 .RightMargin = Application.InchesToPoints(0.4) .LeftMargin = Application.InchesToPoints(0.4) .TopMargin = Application.InchesToPoints(0.75) .HeaderMargin = Application.InchesToPoints(0.25) .BottomMargin = Application.InchesToPoints(0.5) .RightFooter = "Page " & "&P" & " of " & "&N" .RightHeader = "&B&12 " & Date .PrintArea = "A1:G10" .CenterFooter = "" .FooterMargin = Application.InchesToPoints(0.3) .CenterHorizontally = True End With ws.PrintPreview Application.ScreenUpdating = True End Sub -- Gary "Akash" wrote in message oups.com... On Feb 22, 11:15 am, dkinn 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 |
#11
Posted to microsoft.public.excel.programming
|
|||
|
|||
Computer Name with VBA
Thank you Chip.
Eric "Chip Pearson" wrote in message ... 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" wrote in message oups.com... On Feb 22, 11:15 am, dkinn 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 |
#12
Posted to microsoft.public.excel.programming
|
|||
|
|||
Computer Name with VBA
I am using Excel 2003.
Thank you. Eric "dkinn" wrote in message ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Row Height variations from computer to computer on same workbook | Excel Discussion (Misc queries) | |||
Formulaed cell response varies from computer to computer | Excel Discussion (Misc queries) | |||
Display size difference- PC computer vs. Mac computer? | Excel Discussion (Misc queries) | |||
How do I copy all Excel files from old computer to new computer? | Excel Discussion (Misc queries) | |||
Autocomplete works with my home computer but not the office computer | Excel Discussion (Misc queries) |