ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   write error - even when no macros run (https://www.excelbanter.com/excel-programming/314735-write-error-even-when-no-macros-run.html)

Jabba

write error - even when no macros run
 
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


All times are GMT +1. The time now is 12:06 AM.

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