Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-07-2012, 02:03 AM
Colin Legg's Avatar
Colin Legg Colin Legg is offline Variable to rename a tab in a worksheet via VBA Windows 7 32bit Variable to rename a tab in a worksheet via VBA Office 2010 32bit
Expert
 
Join Date: Jan 2011
Location: UK
Posts: 369
Colin Legg will become famous soon enough
Default


Hi Paul,

I'll leave it to the OP to validate his/her assumption that the target sheet will always be the first sheet.

I realised I forgot to post some sample Codename code for the OP, which is the approach I favour.

Code:
Sub demo()
 
    Const strNEW_NAME As String = "File 1"
 
    'a workbook cannot have sheets with duplicate names
    If Not SheetExists(ThisWorkbook, strNEW_NAME) Then
        'sheet1 is the codename of the sheet, determined at design time
        Sheet1.Name = strNEW_NAME
    End If
 
End Sub
 
'a generic function to check if a sheet exists
Private Function SheetExists(ByVal wkbTarget As Workbook, ByRef strName As String)
    On Error Resume Next
    SheetExists = Not wkbTarget.Sheets(strName) Is Nothing
End Function
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Rename a Quick Part sleake Word 14 10-14-2013 09:21 AM
Variable to rename a tab in a worksheet via VBA Run-time error '91': Object variable or With block variable not set tinfanide Excel Programming 2 06-10-2012 10:17 AM
Rename Files gsrikanth Excel Programming 3 05-14-2012 03:03 AM
Variable to rename a tab in a worksheet via VBA "Auto-populating" data-worksheet to worksheet. meggenm Excel 4 02-04-2012 02:04 AM
Variable to rename a tab in a worksheet via VBA Rename File cksm4 Word VBA 2 02-25-2011 09:29 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:12 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft