Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 25th, 2013  |  syntax: None  |  size: 0.78 KB  |  views: 65  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Dim WS As Worksheet
  2.  
  3.      Set WS = Sheets.Add(After:=Sheets(Worksheets.count))
  4.      WS.name = txtSheetName.value
  5.        
  6. Dim WS As Worksheet
  7.   MsgBox (WS Is Nothing)
  8.  
  9.     Set WS = Sheets.Add(After:=Sheets(Worksheets.count))
  10.     '***** Nothing after this point gets processed *******
  11.     MsgBox (WS Is Nothing)
  12.     MsgBox WS.name
  13.  
  14.     WS.name = txtSheetName.value
  15.     MsgBox WS.name
  16.        
  17. Dim WS as Worksheet
  18. Set WS = Sheets.Add
  19.  
  20. You don't have to know where is it located, what's it's name, you just refer to it as WS.
  21.  
  22. If you still want to do this the "old fashioned" way, try this:
  23.  
  24. Sheets.Add.Name = "Test"
  25.        
  26. Dim WS As Worksheet
  27. Dim i As Long
  28.  
  29. With ThisWorkbook
  30.     Set WS = .Worksheets.Add(After:=.Sheets(.Sheets.Count))
  31. End With
  32.  
  33. For i = 1 To 1000
  34.     DoEvents
  35. Next i
  36.  
  37. WS.Name = txtSheetName.Value
clone this paste RAW Paste Data