Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Well, most of the coding for the new quote module user form has been going well. I have however, hit a snag. In the code below there is a section that is causing an error. The debugger is saying the varible is not defined. However, where it is stopping is not exactly a varible. It is the name of a command button placed on the sheet mentioned in the same line. Other than having the code select the right sheet first (already incorporated into the code) I don't know how else to tell VBA that it is a command button on the sheet and not one on the UserForm. Any help will be appreciated. The offending code is as follows: Code: -------------------- ' 'Saves the New Quote in the template and disables the command button ActiveWorkbook.SaveAs ThisWorkbook.Name ActiveWorkbook.Sheets("Start Here").Activate cmdStartWizard.Enabled = False cmdStartWizard.Caption = "Quote Wizard Disabled," & Chr(13) & " please use editing button." ' -------------------- And this is it in context of the entire click event: Code: -------------------- Private Sub Image4_Click() ' ' 'Selects the quote sheet and activates ActiveWorkbook.Sheets("Final Quote").Activate ' 'Changes the Quote Number to Increase by 1 Range("J4").Value = Range("J4").Value + 1 Range("J4").Copy Range("J4").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Application.CutCopyMode = False ' 'Inserts the Deliverable Types into Cell J5 ' ' 'Inserts the TAT and type into Cell M4, and N4 respectivly Sheets("Final Quote").Range("M4").Value = txtTAT.Text Sheets("Final Quote").Range("N4").Value = lbxTAType.Text ' 'Inserts the Project Reference into Cell J7 Sheets("Final Quote").Range("J7").Value = txtProjectReference ' 'Inserts the Company Name into Cell C12 Sheets("Final Quote").Range("C12").Value = cmbClientList ' 'Saves the file with a unique name 'Declares Variables of the file name for saved as function Dim QNum As String Dim CNam As String Dim CrDt As String Dim VNum As String ' 'Defines the variable names from Quote Form CNam = Range("C12").Text CrDt = Format(Now, "mmddyy") VNum = Range("K4").Text ' 'Saves the New Quote in the template and disables the command button ActiveWorkbook.SaveAs ThisWorkbook.Name ActiveWorkbook.Sheets("Start Here").Activate cmdStartWizard.Enabled = False cmdStartWizard.Caption = "Quote Wizard Disabled," & Chr(13) & " please use editing button." ' 'Defines the QNum varible to the new quote number after the template is saved to insure they_ 'are saved with the same number ActiveWorkbook.Sheets("Final Quote").Activate QNum = Range("J4").Text ' 'Saves the New Quote as a unique file ActiveWorkbook.SaveAs _ "X:\_FEE SCHEDULE & QUOTE MODULE\Created Quotes\" & QNum & VNum & "-" & CNam _ & "-" & CrDt ' 'Disables step 1 and Shows step 2 End Sub -------------------- Here's to hope, Amber:) -- Amber_D_Laws ------------------------------------------------------------------------ Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012 View this thread: http://www.excelforum.com/showthread...hreadid=507754 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hello Amber_D_Laws, You can't reference a command button on worksheet the same way you reference it on a UserForm. There are 2 types of command buttons and you don't which you are using, so i will include the referencing methods for both. Forms Toolbar Command Button Example: With ActiveSheet.Shapes("Button 1") TextFrame.Characters.Text = "Quote Wizard Disabled" & vbLf & "please use editing button" ControlFormat.Enabled = False End With Control Toolbox Command Button Example: Dim cmdButton As Object Set cmdButton = ActiveSheet.OLEObjects("CommandButton1").Object cmdButton.Caption = "Quote Wizard Disabled" & vbLf & "please use editing button" cmdButton.Enabled = False Change the command buttons in the examples to their original code names. This is not the same as the caption. This is the name the system used when they were created. Sincerely, Leith Ross -- Leith Ross ------------------------------------------------------------------------ Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465 View this thread: http://www.excelforum.com/showthread...hreadid=507754 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Thanks Leith, It is a Toolbox Command Button, I think. How do I tell the difference to be sure? And by: Leith Ross Wrote: Change the command buttons in the examples to their original code names. This is not the same as the caption. This is the name the system used when they were created. do you mean that I should change it's name from cmdStartWiard back to CommandButton1? I ask because I thought that once a name (as in its (Name) from the properties) was changed you could reference that in code without issue. Is this not always the case? Leith Ross Wrote: Hello Amber_D_Laws, You can't reference a command button on worksheet the same way you reference it on a UserForm. There are 2 types of command buttons and you don't which you are using, so i will include the referencing methods for both. Forms Toolbar Command Button Example: With ActiveSheet.Shapes("Button 1") .TextFrame.Characters.Text = "Quote Wizard Disabled" & vbLf & "please use editing button" .ControlFormat.Enabled = False End With Control Toolbox Command Button Example: Dim cmdButton As Object Set cmdButton = ActiveSheet.OLEObjects("CommandButton1").Object cmdButton.Caption = "Quote Wizard Disabled" & vbLf & "please use editing button" cmdButton.Enabled = False Change the command buttons in the examples to their original code names. This is not the same as the caption. This is the name the system used when they were created. Sincerely, Leith Ross -- Amber_D_Laws ------------------------------------------------------------------------ Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012 View this thread: http://www.excelforum.com/showthread...hreadid=507754 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hello Amber_D_Laws, If you created the command button from the Excel menu then it is Forms type. If you created it using the VBA Toolbar then it is Control Toolbox type. If you still aren't sure, try each code version. You are correct about the name needing to be changed to CommandButton1 When you change the name of the control, it only effects the projec references, not the system reference. Sincerely, Leith Ros -- Leith Ros ----------------------------------------------------------------------- Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846 View this thread: http://www.excelforum.com/showthread.php?threadid=50775 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Before you get all wrapped around the axle,
It sounds like Leith's information is a bit dated. there was a problem with this in xl97, so if you are using xl97 it is a bit more complex, but you can still change the code name of the commandbutton. I assume you are not working with excel 97 and as your subject states, this code is run from a userform module. In that case the unqualified name cmdStartWizard is seen to refer to the Userform where there is no such control. It sounds like the only thing you need to do is qualify the name of the command button with a reference to the sheet so Excle knows where it is. Activesheet.cmdStartWizard.Enabled = False ActiveSheet.cmdStartWizard.Caption = "Quote Wizard Disabled," & Chr(13) & " please use editing -------------- if it isn't the activesheet, then assume it is on Sheet3 Worksheets("Sheet3").Activesheet.cmdStartWizard.En abled = False Worksheets("Sheet3").ActiveSheet.cmdStartWizard.Ca ption = "Quote Wizard Disabled," & Chr(13) & " please use editing --------------------------- Here is a little demo from the immediate window to prove the point. I have one button on Sheet1 named CommandButton1 ' check the name by displaying the caption ? Activesheet.CommandButton1.Caption CommandButton1 'Change the name to cmdStartWizard Activesheet.CommandButton1.Name = "cmdStartWizard" ' Now use the new name to check the caption ? activesheet.cmdStartWizard.Caption CommandButton1 ' Now use the new name to work with the control ' by changing the caption activesheet.cmdStartWizard.Caption = "HokeyPokey" ' Verify that it is changed ? activesheet.cmdStartWizard.Caption HokeyPokey -- Regards, Tom Ogilvy "Leith Ross" wrote in message ... Hello Amber_D_Laws, If you created the command button from the Excel menu then it is a Forms type. If you created it using the VBA Toolbar then it is a Control Toolbox type. If you still aren't sure, try each code version. You are correct about the name needing to be changed to CommandButton1. When you change the name of the control, it only effects the project references, not the system reference. Sincerely, Leith Ross -- Leith Ross ------------------------------------------------------------------------ Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465 View this thread: http://www.excelforum.com/showthread...hreadid=507754 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Tom, Love the "Hokey Pokey" caption in the example, it made me laugh righ out loud much to the confusion of my co-workers. I will try you suggestion and let you all know how it goes from there. Thanks again! Amber Tom Ogilvy Wrote: Before you get all wrapped around the axle, It sounds like Leith's information is a bit dated. there was a proble with this in xl97, so if you are using xl97 it is a bit more complex, bu you can still change the code name of the commandbutton. I assume you are not working with excel 97 and as your subject states, this code is run fro a userform module. In that case the unqualified name cmdStartWizard i seen to refer to the Userform where there is no such control. It sounds like the only thing you need to do is qualify the name o the command button with a reference to the sheet so Excle knows where i is. Activesheet.cmdStartWizard.Enabled = False ActiveSheet.cmdStartWizard.Caption = "Quote Wizard Disabled," & Chr(13 & " please use editing -------------- if it isn't the activesheet, then assume it is o Sheet3 Worksheets("Sheet3").Activesheet.cmdStartWizard.En abled = False Worksheets("Sheet3").ActiveSheet.cmdStartWizard.Ca ption = "Quot Wizard Disabled," & Chr(13) & " please use editing --------------------------- Here is a little demo from the immediate window to prove the point. have one button on Sheet1 named CommandButton1 ' check the name by displaying the caption ? Activesheet.CommandButton1.Caption CommandButton1 'Change the name to cmdStartWizard Activesheet.CommandButton1.Name = "cmdStartWizard" ' Now use the new name to check the caption ? activesheet.cmdStartWizard.Caption CommandButton1 ' Now use the new name to work with the control ' by changing the caption activesheet.cmdStartWizard.Caption = "HokeyPokey" ' Verify that it is changed ? activesheet.cmdStartWizard.Caption HokeyPokey -- Regards, Tom Ogilvy -- Amber_D_Law ----------------------------------------------------------------------- Amber_D_Laws's Profile: http://www.excelforum.com/member.php...fo&userid=3001 View this thread: http://www.excelforum.com/showthread.php?threadid=50775 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Leith, I tried both versions, and got two diffrent error messages with each. I.E. neither worked. I had already changed the name back to CommandButton1, but but I went back and double check just in case. Still no dice. I will try Tom's suggestion and let you both know how it goes. Thanks, Amber Leith Ross Wrote: Hello Amber_D_Laws, If you created the command button from the Excel menu then it is a Forms type. If you created it using the VBA Toolbar then it is a Control Toolbox type. If you still aren't sure, try each code version. You are correct about the name needing to be changed to CommandButton1. When you change the name of the control, it only effects the project references, not the system reference. Sincerely, Leith Ross -- Amber_D_Laws ------------------------------------------------------------------------ Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012 View this thread: http://www.excelforum.com/showthread...hreadid=507754 |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() ***Bump*** Any help is appreciated. Tom has given me great ideas, I jus understand why it still isn't working. ![]() So, Tom if your reading this....Any ideas. or If not Tom please see if you can find something that we missed. Thanks in advance -- Amber_D_Law ----------------------------------------------------------------------- Amber_D_Laws's Profile: http://www.excelforum.com/member.php...fo&userid=3001 View this thread: http://www.excelforum.com/showthread.php?threadid=50775 |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() For two days I have been banging my head against the keyboard trying t find out why Tom's perfectly resonable solution to my problem was no working out. Well....As it turns out while using someone elses advice, I had change the object's name back to CommandButton1, and so, when I changed th code to go along with Tom's advice, I forgot to change the button' name back to what I wanted it to be (as it was used in the code). So of course VBA didn't recognize the object!!!!! There was n cmdStartWizard as far as it was concerned. Eeesh! ![]() own idiocy the was causing the problem. So, this is my offical appology for seeming to be a pest abou something that was not really a problem at all. Thank you Tom for bein as patient as you were, and for giving me the help that in the en worked briliantly and saved the day!:) I am sure that I will continue to have questions as I face the nex three pages of this multi-page user form. I just hope that m carelessness will not prevent others from helping when I need it. would hate to be known as "The Girl that cried Error". Regards, Amber Amber_D_Laws Wrote: ***Bump*** Any help is appreciated. Tom has given me great ideas, I jus understand why it still isn't working. ![]() So, Tom if your reading this....Any ideas. or If not Tom please see if you can find something that we missed. Thanks in advance -- Amber_D_Law ----------------------------------------------------------------------- Amber_D_Laws's Profile: http://www.excelforum.com/member.php...fo&userid=3001 View this thread: http://www.excelforum.com/showthread.php?threadid=50775 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Command Button to Hyperlink to a Different worksheet | Excel Programming | |||
How do I add a command button on a worksheet to "paste" from the . | Excel Worksheet Functions | |||
Command button on a protected worksheet | Excel Programming | |||
Userform disappears when you try to initialize from a command button | Excel Programming | |||
login to worksheet from command button | Excel Programming |