ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   does workbook contain worksheet (https://www.excelbanter.com/excel-programming/312709-does-workbook-contain-worksheet.html)

asmenut

does workbook contain worksheet
 
I am creating a series of userforms that
1) checks if the open workbook contains a specific worksheet.
2) Loads a textbox in the form with data from a cell
3) allows the text to be added to
4) Re-loads the modified text to the cell
5) Saves the worksheet

I am having trouble getting the sheet verification and the textbox to load
the cell text. Any ideas?

Bob Phillips[_6_]

does workbook contain worksheet
 

'-----------------------------------------------------------------
Function SheetExists(Sh As String, _
Optional wb As Workbook) As Boolean
'-----------------------------------------------------------------
Dim oWs As Worksheet
If wb Is Nothing Then Set wb = ActiveWorkbook
On Error Resume Next
SheetExists = CBool(Not wb.Worksheets(Sh) Is Nothing)
On Error GoTo 0
End Function


--

HTH

RP

"asmenut" wrote in message
...
I am creating a series of userforms that
1) checks if the open workbook contains a specific worksheet.
2) Loads a textbox in the form with data from a cell
3) allows the text to be added to
4) Re-loads the modified text to the cell
5) Saves the worksheet

I am having trouble getting the sheet verification and the textbox to load
the cell text. Any ideas?




asmenut

does workbook contain worksheet
 
Thank you Bob. I got the first part to work. Now for the second part,
Getting the TextBox to show the cell data.

Everytime a workbook is open (that contains the Sheet), I get an "Out of
Subscript" error.

Private Sub UserForm_Initialize()
Dim MRange As Range

Sheets("Eo-Cover").Activate
Set MRange = ActiveSheet.Range("B24")
TMAffectText = MRange.Value
End Sub

"Bob Phillips" wrote:


'-----------------------------------------------------------------
Function SheetExists(Sh As String, _
Optional wb As Workbook) As Boolean
'-----------------------------------------------------------------
Dim oWs As Worksheet
If wb Is Nothing Then Set wb = ActiveWorkbook
On Error Resume Next
SheetExists = CBool(Not wb.Worksheets(Sh) Is Nothing)
On Error GoTo 0
End Function


--

HTH

RP

"asmenut" wrote in message
...
I am creating a series of userforms that
1) checks if the open workbook contains a specific worksheet.
2) Loads a textbox in the form with data from a cell
3) allows the text to be added to
4) Re-loads the modified text to the cell
5) Saves the worksheet

I am having trouble getting the sheet verification and the textbox to load
the cell text. Any ideas?





Dave Peterson[_3_]

does workbook contain worksheet
 
maybe...

Private Sub UserForm_Initialize()
if sheetexist("eo-cover",thisworkbook) then
tmaffecttext.text = Sheets("Eo-Cover").Range("B24").value
else
tMAffectText.text = "missing sheet"
end if
End Sub

asmenut wrote:

Thank you Bob. I got the first part to work. Now for the second part,
Getting the TextBox to show the cell data.

Everytime a workbook is open (that contains the Sheet), I get an "Out of
Subscript" error.

Private Sub UserForm_Initialize()
Dim MRange As Range

Sheets("Eo-Cover").Activate
Set MRange = ActiveSheet.Range("B24")
TMAffectText = MRange.Value
End Sub

"Bob Phillips" wrote:


'-----------------------------------------------------------------
Function SheetExists(Sh As String, _
Optional wb As Workbook) As Boolean
'-----------------------------------------------------------------
Dim oWs As Worksheet
If wb Is Nothing Then Set wb = ActiveWorkbook
On Error Resume Next
SheetExists = CBool(Not wb.Worksheets(Sh) Is Nothing)
On Error GoTo 0
End Function


--

HTH

RP

"asmenut" wrote in message
...
I am creating a series of userforms that
1) checks if the open workbook contains a specific worksheet.
2) Loads a textbox in the form with data from a cell
3) allows the text to be added to
4) Re-loads the modified text to the cell
5) Saves the worksheet

I am having trouble getting the sheet verification and the textbox to load
the cell text. Any ideas?





--

Dave Peterson



All times are GMT +1. The time now is 09:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com