Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
SMac
 
Posts: n/a
Default Template for tab not whole document

I have a worksheet that the first tab is the template named "Template", what
I want to happen is I have a command button on the form called "New Entry"
which copies the tab and makes "Template (2)" but thinking ahead some people
may forget to hit the command button and start entering into the original
template.
I tried to just lock the sheet but then the lock carries over to the copied
template.

My current code is:

Sub NewForm()
Sheets("Template").Select
Sheets("Template").Copy After:=Sheets(1)
End Sub

Could I add some code at the end to tell the copy to unprotect?

Thanks!!
Stacey
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

Password protect the worksheet Template.

Then unprotect the copy:

Option Explicit
Sub NewForm2()
Sheets("Template").Copy After:=Sheets(1)
ActiveSheet.Unprotect Password:="hi"
End Sub




???? wrote:

I have a worksheet that the first tab is the template named "Template", what
I want to happen is I have a command button on the form called "New Entry"
which copies the tab and makes "Template (2)" but thinking ahead some people
may forget to hit the command button and start entering into the original
template.
I tried to just lock the sheet but then the lock carries over to the copied
template.

My current code is:

Sub NewForm()
Sheets("Template").Select
Sheets("Template").Copy After:=Sheets(1)
End Sub

Could I add some code at the end to tell the copy to unprotect?

Thanks!!
Stacey


--

Dave Peterson
  #3   Report Post  
SMac
 
Posts: n/a
Default

Worked like a charm!!

I have another question for you, on this form there is another command
button "Save Form" which I would like it to take data from cell K8 and use
that as the tab name, if there isn't a name to use "Need Asset #-1" but if
there is already an "Need Asset #-1" make the next one +1 "Need Asset #-2".

Sounds like a messy way but when this form is first filled out there isn't
an Asset # assigned until its been approved by all directors then #'s are
assigned.

Thanks again!!

"Dave Peterson" wrote:

Password protect the worksheet Template.

Then unprotect the copy:

Option Explicit
Sub NewForm2()
Sheets("Template").Copy After:=Sheets(1)
ActiveSheet.Unprotect Password:="hi"
End Sub




???? wrote:

I have a worksheet that the first tab is the template named "Template", what
I want to happen is I have a command button on the form called "New Entry"
which copies the tab and makes "Template (2)" but thinking ahead some people
may forget to hit the command button and start entering into the original
template.
I tried to just lock the sheet but then the lock carries over to the copied
template.

My current code is:

Sub NewForm()
Sheets("Template").Select
Sheets("Template").Copy After:=Sheets(1)
End Sub

Could I add some code at the end to tell the copy to unprotect?

Thanks!!
Stacey


--

Dave Peterson

  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

What happens if the value in K8 already has a worksheet associated with it?

Option Explicit
Sub testme02()
Dim myStr As String
Dim iCtr As Long
With ActiveSheet
myStr = .Range("K8").Value
If Trim(myStr) < "" Then
On Error Resume Next
.Name = myStr
If Err.Number < 0 Then
MsgBox "Duplicate Asset in K8--fix and try again"
Err.Clear
End If
On Error GoTo 0
Else
myStr = "Need Asset #-"
iCtr = 1
Do
On Error Resume Next
.Name = myStr & iCtr
If Err.Number = 0 Then
'get out
Exit Do
Else
iCtr = iCtr + 1
Err.Clear
End If
Loop
On Error GoTo 0
End If
End With
End Sub



SMac wrote:

Worked like a charm!!

I have another question for you, on this form there is another command
button "Save Form" which I would like it to take data from cell K8 and use
that as the tab name, if there isn't a name to use "Need Asset #-1" but if
there is already an "Need Asset #-1" make the next one +1 "Need Asset #-2".

Sounds like a messy way but when this form is first filled out there isn't
an Asset # assigned until its been approved by all directors then #'s are
assigned.

Thanks again!!

"Dave Peterson" wrote:

Password protect the worksheet Template.

Then unprotect the copy:

Option Explicit
Sub NewForm2()
Sheets("Template").Copy After:=Sheets(1)
ActiveSheet.Unprotect Password:="hi"
End Sub




???? wrote:

I have a worksheet that the first tab is the template named "Template", what
I want to happen is I have a command button on the form called "New Entry"
which copies the tab and makes "Template (2)" but thinking ahead some people
may forget to hit the command button and start entering into the original
template.
I tried to just lock the sheet but then the lock carries over to the copied
template.

My current code is:

Sub NewForm()
Sheets("Template").Select
Sheets("Template").Copy After:=Sheets(1)
End Sub

Could I add some code at the end to tell the copy to unprotect?

Thanks!!
Stacey


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
SMac
 
Posts: n/a
Default

Sweet!!!! 2 for 2, that was a lot more complicated then I was trying to do.
Thanks for your time!

"Dave Peterson" wrote:

What happens if the value in K8 already has a worksheet associated with it?

Option Explicit
Sub testme02()
Dim myStr As String
Dim iCtr As Long
With ActiveSheet
myStr = .Range("K8").Value
If Trim(myStr) < "" Then
On Error Resume Next
.Name = myStr
If Err.Number < 0 Then
MsgBox "Duplicate Asset in K8--fix and try again"
Err.Clear
End If
On Error GoTo 0
Else
myStr = "Need Asset #-"
iCtr = 1
Do
On Error Resume Next
.Name = myStr & iCtr
If Err.Number = 0 Then
'get out
Exit Do
Else
iCtr = iCtr + 1
Err.Clear
End If
Loop
On Error GoTo 0
End If
End With
End Sub



SMac wrote:

Worked like a charm!!

I have another question for you, on this form there is another command
button "Save Form" which I would like it to take data from cell K8 and use
that as the tab name, if there isn't a name to use "Need Asset #-1" but if
there is already an "Need Asset #-1" make the next one +1 "Need Asset #-2".

Sounds like a messy way but when this form is first filled out there isn't
an Asset # assigned until its been approved by all directors then #'s are
assigned.

Thanks again!!

"Dave Peterson" wrote:

Password protect the worksheet Template.

Then unprotect the copy:

Option Explicit
Sub NewForm2()
Sheets("Template").Copy After:=Sheets(1)
ActiveSheet.Unprotect Password:="hi"
End Sub




???? wrote:

I have a worksheet that the first tab is the template named "Template", what
I want to happen is I have a command button on the form called "New Entry"
which copies the tab and makes "Template (2)" but thinking ahead some people
may forget to hit the command button and start entering into the original
template.
I tried to just lock the sheet but then the lock carries over to the copied
template.

My current code is:

Sub NewForm()
Sheets("Template").Select
Sheets("Template").Copy After:=Sheets(1)
End Sub

Could I add some code at the end to tell the copy to unprotect?

Thanks!!
Stacey

--

Dave Peterson


--

Dave Peterson



  #6   Report Post  
SMac
 
Posts: n/a
Default

Sorry Dave, Excel code is not my forte but I have thought of one more
challenge, is there code I can write so none of the sheets can be deleted
without a password?

Thanks!

"Dave Peterson" wrote:

What happens if the value in K8 already has a worksheet associated with it?

Option Explicit
Sub testme02()
Dim myStr As String
Dim iCtr As Long
With ActiveSheet
myStr = .Range("K8").Value
If Trim(myStr) < "" Then
On Error Resume Next
.Name = myStr
If Err.Number < 0 Then
MsgBox "Duplicate Asset in K8--fix and try again"
Err.Clear
End If
On Error GoTo 0
Else
myStr = "Need Asset #-"
iCtr = 1
Do
On Error Resume Next
.Name = myStr & iCtr
If Err.Number = 0 Then
'get out
Exit Do
Else
iCtr = iCtr + 1
Err.Clear
End If
Loop
On Error GoTo 0
End If
End With
End Sub



SMac wrote:

Worked like a charm!!

I have another question for you, on this form there is another command
button "Save Form" which I would like it to take data from cell K8 and use
that as the tab name, if there isn't a name to use "Need Asset #-1" but if
there is already an "Need Asset #-1" make the next one +1 "Need Asset #-2".

Sounds like a messy way but when this form is first filled out there isn't
an Asset # assigned until its been approved by all directors then #'s are
assigned.

Thanks again!!

"Dave Peterson" wrote:

Password protect the worksheet Template.

Then unprotect the copy:

Option Explicit
Sub NewForm2()
Sheets("Template").Copy After:=Sheets(1)
ActiveSheet.Unprotect Password:="hi"
End Sub




???? wrote:

I have a worksheet that the first tab is the template named "Template", what
I want to happen is I have a command button on the form called "New Entry"
which copies the tab and makes "Template (2)" but thinking ahead some people
may forget to hit the command button and start entering into the original
template.
I tried to just lock the sheet but then the lock carries over to the copied
template.

My current code is:

Sub NewForm()
Sheets("Template").Select
Sheets("Template").Copy After:=Sheets(1)
End Sub

Could I add some code at the end to tell the copy to unprotect?

Thanks!!
Stacey

--

Dave Peterson


--

Dave Peterson

  #7   Report Post  
Dave Peterson
 
Posts: n/a
Default

You could protect the workbook:

Tools|Protection|Protect Workbook|and make sure Structure is checked.

This means that you can't move worksheets, add or delete worksheets or even
rename them.

If you record a macro when you lock the workbook, you'll see the code you need
to add so that your copying of Template still works (as well as the renaming of
sheets).

Your code would look something like:

ThisWorkbook.Unprotect Password:="hithere"
'do all your stuff
ThisWorkbook.Protect structu=True, Windows:=False, Password:="hithere"


Thisworkbook is the workbook that contains the code. I assumed that your code
is in the same workbook--if it isn't, then maybe activeworkbook.unprotect....

And you'll have to provide a macro that gives the user the ability to delete any
sheet.

It would unprotect the workbook, delete the sheet, and then reprotect the
workbook.

Be aware that both this type of workbook protection and worksheet protection is
easily broken by almost anyone interested enough to find these newsgroups.



SMac wrote:

Sorry Dave, Excel code is not my forte but I have thought of one more
challenge, is there code I can write so none of the sheets can be deleted
without a password?

Thanks!

"Dave Peterson" wrote:

What happens if the value in K8 already has a worksheet associated with it?

Option Explicit
Sub testme02()
Dim myStr As String
Dim iCtr As Long
With ActiveSheet
myStr = .Range("K8").Value
If Trim(myStr) < "" Then
On Error Resume Next
.Name = myStr
If Err.Number < 0 Then
MsgBox "Duplicate Asset in K8--fix and try again"
Err.Clear
End If
On Error GoTo 0
Else
myStr = "Need Asset #-"
iCtr = 1
Do
On Error Resume Next
.Name = myStr & iCtr
If Err.Number = 0 Then
'get out
Exit Do
Else
iCtr = iCtr + 1
Err.Clear
End If
Loop
On Error GoTo 0
End If
End With
End Sub



SMac wrote:

Worked like a charm!!

I have another question for you, on this form there is another command
button "Save Form" which I would like it to take data from cell K8 and use
that as the tab name, if there isn't a name to use "Need Asset #-1" but if
there is already an "Need Asset #-1" make the next one +1 "Need Asset #-2".

Sounds like a messy way but when this form is first filled out there isn't
an Asset # assigned until its been approved by all directors then #'s are
assigned.

Thanks again!!

"Dave Peterson" wrote:

Password protect the worksheet Template.

Then unprotect the copy:

Option Explicit
Sub NewForm2()
Sheets("Template").Copy After:=Sheets(1)
ActiveSheet.Unprotect Password:="hi"
End Sub




???? wrote:

I have a worksheet that the first tab is the template named "Template", what
I want to happen is I have a command button on the form called "New Entry"
which copies the tab and makes "Template (2)" but thinking ahead some people
may forget to hit the command button and start entering into the original
template.
I tried to just lock the sheet but then the lock carries over to the copied
template.

My current code is:

Sub NewForm()
Sheets("Template").Select
Sheets("Template").Copy After:=Sheets(1)
End Sub

Could I add some code at the end to tell the copy to unprotect?

Thanks!!
Stacey

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to embed Word document into Excel and retain sizing, formatti. Kent Excel Discussion (Misc queries) 0 February 2nd 05 07:37 PM
how to send documents from document imaging to word? JBHarriman Excel Discussion (Misc queries) 0 January 30th 05 07:31 PM
Excel should not delete document after trying to send email 4rs Excel Discussion (Misc queries) 0 January 14th 05 04:39 AM
Need TEMPLATE for Document Management marsar Excel Discussion (Misc queries) 1 December 23rd 04 03:45 PM
Hyperlink to word document problem JS Links and Linking in Excel 0 December 8th 04 10:54 PM


All times are GMT +1. The time now is 12:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"