I have to amend my last suggestion: a oneliner suffices:
Sub M_snb() if not evaluate("isref(" & shtName &"!A1)") then thisworkbook.sheets.add.name=shtname End Sub
I have to amend my last suggestion: a oneliner suffices:
Sub M_snb() if not evaluate("isref(" & shtName &"!A1)") then thisworkbook.sheets.add.name=shtname End Sub
Hi snb, Because I run the macro from the Personal Workbook I have adapted your proposed code to the following: [vba]If Not Evaluate("isref(" & shtName & "!A1)") Then BeginBook.Sheets.Add.Name = shtName BeginBook.shtName.Move After:=ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.Count) 'Moves it to the last "tab" position.[/vba] I ran the code before the change and it added another sheet to the Personal Workbook, called "Sheet4(BrokenLinksList)" in the VBA Project window. How do I get rid of this sheet? Regards, Henk
Check the difference between 'ThisWorkbook' and 'Activeworkbook' in the VBEditor's helpfiles.
Use:
Sub M_snb() If Not evaluate("isref(" & shtName &"!A1)") Then ActiveWorkbook.sheets.add.name=shtname End Sub
Thanks,
ThisWorkBook object refers to the workbook that the code is contained in. ActiveWorkBook object refers to the workbook that is currently active.
What I would like to know is whether there is a performance difference between referring to it as an excel element instead of a workbook element.
vanhunk
Have a look:
Sub M_snb() msgbox "isref(" & shtName &"!A1)" If Not evaluate("isref(" & shtName &"!A1)") Then ActiveWorkbook.sheets.add.name=shtname End Sub
If you need to concatenate a string & a non-string (number, variable, date, Range value, object property) you need to use the concatenation operator &
msgbox "abc " & 5 msgbox "abc" & variables msgbox "abc" & range("A5").value msgbox "abc " & Date msgbox "abc " & Now msgbox "abc " & activeworkbook.name