Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Morning all,
I am having major problems I am using a combo box (cmbindivlist) on a form (frmindiv) which is populated from a column on form (d1) to view existing worksheets or create a new one if it doesn't exist! I tried: ------------------------------------------------------------------------ Private Sub cmdviewi_Click() If Cmbindivlist.ListIndex -1 Then indivsh = Cmbindivlist.Name If sheetexists(indivsh) Then Sheets(Cmbindivlist.Name).Select Else: Call makesheeti End If Sheets(indivsh).Visible = True Range("a1:a1").Select End If End Sub the sheetexsts function is in a separate module: Public Function sheetexists(ByVal indivsh) As Boolean ' Returns TRUE if sheet exists in the active workbook Dim x As Object On Error Resume Next Set x = ActiveWorkbook.Sheets(indivsh) If Err = 0 Then sheetexists = True Else: sheetexists = False End Function (obtained and tweaked from this site) ------------------------------------------------------------------------- But that didbn't work no matter how many times I tweaked and fiddled. Then I tried: ----------------------------------------------- Private Sub cmdviewi_Click() If Cmbindivlist.ListIndex -1 Then indivsh = Cmbindivlist.Text For Each wks In Worksheets If wks.Name = indivsh Then Sheets(Cmbindivlist.Text).Select On Error GoTo makesheeta Exit Sub End If Next wks makesheeta: Sheets("template").Copy befo=Sheets("template") ActiveSheet.Name = indivsh End If End Sub ------------------------------------------------- which appeared to work....if the sheet existed it gave it focus and brought it to the front and if the sheet didn't exist it copied te template and renamed it to the selected name from the combo box! Wey Hey you're thinking (I know I did!) - but no!!!!!! THE HORROR!!!!!! Write this code to a workbook and excel produces a 'memory could not be written' error, closes down, locks my 'personal macro' file for editing, and lets you open the file again only as 'read only' or 'notify' etc.. unless you restart the PC EVEN IF YOU DON'T RUN THIS OR ANY OTHER MACRO IN THE WORKBOOK!!!!!!!! EVEN IF YOU DON'T SAVE ANYTHING! - JUST OPEN AND CLOSE IT! Please help before I lose ALL my hair! -- Jabba |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel 2000 with macros slows to write to W2k3/XP disk or shares | Excel Discussion (Misc queries) | |||
How to write macros | Excel Discussion (Misc queries) | |||
Macros that write data to a new spreadsheet? | Excel Programming | |||
Error when using macro to write formula to cell | Excel Programming | |||
Possible to write Excel macros in JavaScript? | Excel Programming |