excel vba - 2 problems

i have set it up so that when they click a command button i
automatically saves the invoice sheet into my documents with the K
cell contents as the file name. However, i would like to have it set u
so that one they close, the next time they open the sheet to do anothe
invoice it will be 1 number higher than the last saved invoice number
The reply posted before took care of most of that, but now it seem
that when i click the command button to auto save it to my docs an
close the sheet, when i open a new sheet it comes up as the sam
number. Should there be some sort of loop code in there?

code: With Sheets("sheet1")
.Range("K5").Value = .Range("K5").Value + 1
End With


Second problem is when i have a userform show and there are two comman
buttons that can be clicked inside of it, how can i set it up so tha
commandbutton2 does not appear until commandbutton1 is clicked on?

is that possible?  I tried some load and hide codes but my knowledge i
limited

thank

--
Message posted from http://www.ExcelForum.com

0
7/8/2004 2:22:47 PM
excel.misc 78881 articles. 5 followers. Follow

10 Replies
605 Views

Similar Articles

[PageSpeed] 1

Hi

on your first question:
could you copy & paste ALL the command button code to save and close the
sheet - it sounds like the close is happening before the number is being
updated.

on your second question:
you can use the visible property of the command button
in design view set the visible property to false for commandbutton2 and then
in commandbutton1's onclick code type
commandbutton2.visible = true

Cheers
JulieD





"chief >" <<chief.192wzx@excelforum-nospam.com> wrote in message
news:chief.192wzx@excelforum-nospam.com...
> i have set it up so that when they click a command button it
> automatically saves the invoice sheet into my documents with the K5
> cell contents as the file name. However, i would like to have it set up
> so that one they close, the next time they open the sheet to do another
> invoice it will be 1 number higher than the last saved invoice number.
> The reply posted before took care of most of that, but now it seems
> that when i click the command button to auto save it to my docs and
> close the sheet, when i open a new sheet it comes up as the same
> number. Should there be some sort of loop code in there?
>
> code: With Sheets("sheet1")
> Range("K5").Value = .Range("K5").Value + 1
> End With
>
>
> Second problem is when i have a userform show and there are two command
> buttons that can be clicked inside of it, how can i set it up so that
> commandbutton2 does not appear until commandbutton1 is clicked on?
>
> is that possible?  I tried some load and hide codes but my knowledge is
> limited
>
> thanks
>
>
> ---
> Message posted from http://www.ExcelForum.com/
>


0
JulieD1 (2295)
7/8/2004 2:48:42 PM
Hi!

Or you could do the job with just one button if that suited you. Chang
the caption according to its function at the time and read the captio
property to check which mode it is in.

Al

--
Message posted from http://www.ExcelForum.com

0
7/8/2004 3:22:26 PM
thanks for the help julie, i actually made the 2 command buttons int
one to make it easier.  It is now set up as 

Private Sub CommandButton1_Click()
Sheet1.SaveAs FileName:="H:\MyDocs\" & Range("K5").Value
Range("A1:M51").PrintOut  

End Sub

What code can be used in order to close the whole sheet once th
save/print command button is clicked.  I tried to do a sort o
sheet1.hide but that doesn't allow it, any ideas?  Why would it be tha
the invoice numbering is not working properly

--
Message posted from http://www.ExcelForum.com

0
7/8/2004 5:24:46 PM
Hi chief

you can't actually close a sheet - you can only close the workbook and this
can be done with the following line of code

ActiveWorkbook.Close

if you click on the word "close" once you've typed it into your code and
press F1 you can find out about the other parameters that it takes.

let us know how you go

Cheers
JulieD



"chief >" <<chief.1935f8@excelforum-nospam.com> wrote in message
news:chief.1935f8@excelforum-nospam.com...
> thanks for the help julie, i actually made the 2 command buttons into
> one to make it easier.  It is now set up as
>
> Private Sub CommandButton1_Click()
> Sheet1.SaveAs FileName:="H:\MyDocs\" & Range("K5").Value
> Range("A1:M51").PrintOut
>
> End Sub
>
> What code can be used in order to close the whole sheet once the
> save/print command button is clicked.  I tried to do a sort of
> sheet1.hide but that doesn't allow it, any ideas?  Why would it be that
> the invoice numbering is not working properly?
>
>
> ---
> Message posted from http://www.ExcelForum.com/
>


0
JulieD1 (2295)
7/9/2004 3:10:00 AM
Thanks for helping me straighten that out, but i am still running int
trouble with this dang invoice numbering.  This is what i have and s
far it doesn't work properly

in sheet1 i have:

Private Sub CommandButton1__Click()
UserForm1.Show
End Sub


In this workbook i have:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Range("K5").Value = Range("K5").Cells + 1

End Sub

Private Sub Workbook_Open()
Range("K3") = Now()
Range("K3").NumberFormat = "mmmm d, yyyy"
Range("K5").NumberFormat = "0000"
If Range("L8").Value >= 1 Then
Range("K5").Value = Range("L8").Value + 1
End If
End Sub


In the userform i have:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode A
Integer)
If CloseMode <> 1 Then Cancel = 1

End Sub


Private Sub CommandButton1_Click()
Sheet1.SaveAs FileName:="H:\MyDocs\" & Range("K5").Value
Range("A1:M51").PrintOut
ActiveWorkbook.Close

End Sub


my goal is to set it up so that when they click on the shortcut to th
Invoice_Retail file, the invoice number will come up for the very firs
time as 0001.  They will enter the info, click the command button fo
save/print/close.  This will save the sheet as 0001 in my document
location.  They can then click on the shortcut again to start wit
0002, and so on...or they can revisit the 0001 saved file in my doc
for recall information purposes.  Is there maybe a way to save only th
K5 (invoice number) cell in the template sheet so that when the shee
is opened the next time it will read that number and increment it b
0001, and hopefully not save the rest of the information in th
template sheet such as customer name, etc.?  I just want to have 
sheet which will open as a new number everytime, and save it to 
location, and then be able to open another sheet and have it be 
number higher than the last.  I have been racking my brain trying t
get it to work, please help before i go craz

--
Message posted from http://www.ExcelForum.com

0
7/9/2004 11:57:43 AM
Hi Chief

the reason its not working is that you're not saving the invoice number ever
....what you need to do is SAVE the workbook in the
Private Sub CommandButton1_Click() code
    ActiveWorkbook.Save
    Sheet1.SaveAs FileName:="H:\MyDocs\" & Range("K5").Value
    Range("A1:M51").PrintOut
    ActiveWorkbook.Close
End Sub

then add in some workbook_open code (in the ThisWorkbook module) that clears
the contents of all the cells that you don't want stuff saved in (excluding
K5), move the invoice number incrementing code to here as well

e.g.
    Range("A1:A10").clearcontents

Hope this helps
Cheers
JulieD


"chief >" <<chief.194ky5@excelforum-nospam.com> wrote in message
news:chief.194ky5@excelforum-nospam.com...
> Thanks for helping me straighten that out, but i am still running into
> trouble with this dang invoice numbering.  This is what i have and so
> far it doesn't work properly
>
> in sheet1 i have:
>
> Private Sub CommandButton1__Click()
> UserForm1.Show
> End Sub
>
>
> In this workbook i have:
>
> Private Sub Workbook_BeforeClose(Cancel As Boolean)
> Range("K5").Value = Range("K5").Cells + 1
>
> End Sub
>
> Private Sub Workbook_Open()
> Range("K3") = Now()
> Range("K3").NumberFormat = "mmmm d, yyyy"
> Range("K5").NumberFormat = "0000"
> If Range("L8").Value >= 1 Then
> Range("K5").Value = Range("L8").Value + 1
> End If
> End Sub
>
>
> In the userform i have:
>
> Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
> Integer)
> If CloseMode <> 1 Then Cancel = 1
>
> End Sub
>
>
> Private Sub CommandButton1_Click()
> Sheet1.SaveAs FileName:="H:\MyDocs\" & Range("K5").Value
> Range("A1:M51").PrintOut
> ActiveWorkbook.Close
>
> End Sub
>
>
> my goal is to set it up so that when they click on the shortcut to the
> Invoice_Retail file, the invoice number will come up for the very first
> time as 0001.  They will enter the info, click the command button for
> save/print/close.  This will save the sheet as 0001 in my documents
> location.  They can then click on the shortcut again to start with
> 0002, and so on...or they can revisit the 0001 saved file in my docs
> for recall information purposes.  Is there maybe a way to save only the
> K5 (invoice number) cell in the template sheet so that when the sheet
> is opened the next time it will read that number and increment it by
> 0001, and hopefully not save the rest of the information in the
> template sheet such as customer name, etc.?  I just want to have a
> sheet which will open as a new number everytime, and save it to a
> location, and then be able to open another sheet and have it be 1
> number higher than the last.  I have been racking my brain trying to
> get it to work, please help before i go crazy
>
>
> ---
> Message posted from http://www.ExcelForum.com/
>


0
JulieD1 (2295)
7/9/2004 12:17:50 PM
JulieD you are an absolute genius!

that is now working great.

This is the last time I'll bug you, when it does save to my docs as i
is doing, if i go into my docs and open 0001 for example, it will go u
to the next number?  is there maybe a way to lock that cell or th
sheet once it has saved itself in my docs?

once again thank you a millio

--
Message posted from http://www.ExcelForum.com

0
7/9/2004 2:11:39 PM
Hi Chief

sorry ... didn't think about the code running when the other books are open
.... so how about this idea:

change the
Private Sub CommandButton1_Click() code
    Sheets("sheet1").Copy
    ActiveWorkbook.SaveAs FileName:="H:\MyDocs\" & Range("K5").Value
    ActiveWorkbook.Close
    Range("A1:M51").PrintOut
    Range("k5") = Range("k5") + 1
    ActiveWorkbook.Close True
End sub

and take the incrementing of the number out of the "this workbook" code.

Cheers
JulieD

"chief >" <<chief.194r5c@excelforum-nospam.com> wrote in message
news:chief.194r5c@excelforum-nospam.com...
> JulieD you are an absolute genius!
>
> that is now working great.
>
> This is the last time I'll bug you, when it does save to my docs as it
> is doing, if i go into my docs and open 0001 for example, it will go up
> to the next number?  is there maybe a way to lock that cell or the
> sheet once it has saved itself in my docs?
>
> once again thank you a million
>
>
> ---
> Message posted from http://www.ExcelForum.com/
>


0
JulieD1 (2295)
7/9/2004 3:01:15 PM
hello Julie

thanks for helping me out so far.  I tried the code you mentioned ye
when i attempt to click the command button it shows an error reading:
"Copy Method of Worksheet class failed"??

any ideas

--
Message posted from http://www.ExcelForum.com

0
7/13/2004 2:35:03 PM
Hi Chief

no, not really :)

when you press the DEBUG button is a line of code highlighted?

do you want to zip up your workbook & email it to me direct and i'll take a
look at it ...
PS what version of excel are you using?

Cheers
JulieD
julied_ng  at hcts  dot net dot au


"chief >" <<chief.19c6wd@excelforum-nospam.com> wrote in message
news:chief.19c6wd@excelforum-nospam.com...
> hello Julie
>
> thanks for helping me out so far.  I tried the code you mentioned yet
> when i attempt to click the command button it shows an error reading:
> "Copy Method of Worksheet class failed"??
>
> any ideas?
>
>
> ---
> Message posted from http://www.ExcelForum.com/
>


0
JulieD1 (2295)
7/13/2004 2:49:45 PM
Reply:

Similar Artilces:

Possible MSVCRT.dll problem
I get these errors when trying to install any version of Iomega's EMC = Retrospect Express HD for Windows. Using Windows 2000 Prof. =20 Any help would be greatly appreciated! Pls post and also email to me = at brotherdave@bigfoot.com. Thanks! Bob MSVCRT.dll for Win32 Error: MSVCRT.dll is not compatible with Win32s. The application failed to initialize properly [0xc0000142]. Click on OK = to terminate the application. How does your question pertain to Outlook Express functionality? EMC� Retrospect� Express HD - System Requirements http://www.retrospect.com/pro...

CList problem: double entries...
I'm having trouble workin with a simple CList: the function always adds the first element twice and I don't know why. also, the later added elements do not appear immediately in the list, but only on the next function call... here is the code: ---------------- CList<CASystem, CASystem> AllCAS; CASystem *GetCreateCASystem(int ID) { bool bFound = false; CASystem *pCAS = NULL; // check if AS list exists if(AllCAS.IsEmpty()) { // create new AS pCAS = new CASystem; pCAS->ID = ID; ...

How do I create project schedule using excel
I need to create a project schedule using excel. Please help. Hi lack of details :-) Maybe give some more information what you're trying to do? -- Regards Frank Kabel Frankfurt, Germany raeisza wrote: > I need to create a project schedule using excel. Please help. ...

Printing an Excel doucument
In this example, I have a document of 100 pages, when I print the document, the column headers only print on the first page and not the subsequent pages. also I would like all the pages to be numbered. is therea fix for this? Hi Richard, For your first question goto File>Page Setup>Sheet tab and look for the option 'Rows to repeat at top' For your second question goto View>Header and Footer and look at the &[page] and &[pages] options in your footer. HTH Martin ...

Beware apparent Tax Estimator problem in M+
The Tax Line Manager shows a "tax category" (my term for lack of a better name--these are kinda cryptic like budget groups) called "State taxes" as being associated with Schedule A. I have a category "Taxes : State Income Tax - previous year" associated with "State taxes". Tax Line Manager shows amounts from transactions categorized as "Taxes : State Income Tax - previous year". So far so good. And there it stops. Tax Estimator doesn't add the amounts from this "State taxes" tax category into the "Deductible Taxes"...

my printer ejects a blank sheet prior to printing with EXCEL
...

Excel: extract and sum numerals from mixed text/numeral cell range
I have a large (30x20) grid of cells with data, and I want to extract and then sum up certain numerals from this entire range. The catch is that the data is mixed numerals and text, as you'll see below. Here's an abbreviated 3x3 example, with a value in each of the nine cells: V7.1 T H P1 A T B V3 P4.5 If I just wanted to sum up the instances of "T" appearing, I could use COUNTIF() for the entire range to come up with answer ("T" appears 2 times). Easy enough. But, what I'm trying to accomplish is to sum up the numerals associated w...

Error in formula displayed for linear and 2nd order curve fits in Excel 2003
I have created trendlines for some pretty simple data using both 2nd order polynomial and linear fits. In both cases, the displayed formulas have their 1st and 2nd order coefficients wrong by a factor of 10!! (I have read lots of posts about increasing precision but this is not what I am up against). Has anyone seen this? What version of Excel? Could you include the data in a follow up post (not as an attachment), along with the coefficients you've computed? - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions Peltier Technical Services, Inc. - http://PeltierT...

Windows Update
My problem is similar to someone else's below(about Excel 2003 not being able to update), the only difference is that I don't want Excel to update at all. I don't even use it. But the yellow shield kept telling me that it had 1 update available, which was Excel 2003, so, out of annoyance, I installed it. After failing to install several times, I decided to uninstall Excel from Microsoft Office(Pro Edition 2003). Even after uninstalling Excel, I still got the windows update alert. How do I stop it? Extra info: When windows update first appeared, I did a custom instal...

excel axes
how do I create a secondary horizontal axis on an xy scatter plot? forgot to mention 2008 excel using Leopard (10.5.2) ...

Excel program
I have a simple program in excel for data entry. When I protect the sheet, and use tab to move about within the spreadsheet, sometimes the tab button will not move the cursor to the next cell. It will pick a random cell to go to next. Is there a way that I can designate what cell it will go to next. Thanks for your help, jb On a protected sheet, it is going to the next unprotected cell. So, if you don't want it to go to a cell, protect it. "JB" <jgblanton@hotmail.com> wrote in message news:093a01c391d0$ae57f190$a301280a@phx.gbl... > I have a simple program in exce...

2003 Excel and 2007 Trial Version Excel
I downloaded the 2007 trial version of Microsoft Office. Now my trial is over and I reloaded my 2003 version. But it will not let me remove the 2007 trial version. Also when I go into my 2003 Excel a Window Installer box comes up that says Preparing to install and this stays on for about 5 minutes before it goes away. I know that I should not have downloaded the trial version but I did. Can someone please help me. I have Windows XP and it is my office computer. Please help! ...

Error Message When opening Excel
I am using Windows VISTA 64 bit O/S with Office Professional 2003 All of a sudden I started to get the following error message: 'One of your object libraries (Stdole32.tlb) is missing or damaged. Please run setup to install it' I am at a loss as how to correct this. I checked online and found some instructions that were for Windows 2000 Those did not work for VISTA at all. Thank you in advance for your support and suggestions, HankL It is telling you to do a "setup to install" on the Office product, did you try that? Did you try doing a repair on ...

MFC: Excel Automation Can't Quit from Excel. Please help...
Hi I use MFC Visual C++ 4.2. I am automating Excel from my application. My problem is I cannot quit the Excel after the automation process finished! I checked it still exists on the Process lists and the most DANGEROUS is everytime the automation function run, it create other Excel and so on. So it must be out of memory soon. I have used the app.Quit() method like all the people used but it DOES NOT work. What should I do? Thank you. I happened to answer this on the office.developer.vba newsgroup. You most likely have neglected to Release() the automation object. joe On Wed, 3 Sep...

Excel number / date conversion
I've just pulled some data out of an ODBC connection into Access an then exported it to Excel. The dates are currently in the format 20031109. But the built in dat convertor (from Format Cells) doesn't do anything, even if I convert i to a 'proper' number first. How can I convert this to 09/11/2003 so that I can do some date - base arithmetic and work out difference in days -- markperr ----------------------------------------------------------------------- markperry's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=2759 View this thread: http://w...

Excel charts should allow "switching" series on or off
A plot (chart) of time series data may be used for many purposes. From my use two reasons I use such plots are: Studying individual time series trends; and Overall impression of all results. But when studying multiple time series data a chart can become cluttered. It would be useful if individual series could be seleceted as visible or invisible so that they could be evaluated without losing the total plot. At the moment the only way to "unclutter" the plot is to remove the temporaily-unwanted series but it can be time consuming to reconstruct the plot. ---------------- Thi...

Email from Excel #3
Is it possible to have Excel send an email if the value of a certain cell is changed? Hi see your post in public.excel -- Regards Frank Kabel Frankfurt, Germany "berj" <berj@adelphia.net> schrieb im Newsbeitrag news:CcSdndsVDJy4jcjcRVn-pQ@adelphia.com... > Is it possible to have Excel send an email if the value of a certain cell is > changed? > > ...

version excel
bonjour a tous, & a tous les pro bien sur es qu'il est possible ,que des l'instant on modifie le code VBA EXCEL on incremente un compteur pour les mise a jour cela me semble plus simple merci pour vos reponse patrick.villa@laposte.net +++++ http://www.mcgimpsey.com/excel/udfs/sequentialnums.html -- --- HTH Bob (change the xxxx to gmail if mailing direct) "pounet" <patrick.villa@laposte.net> wrote in message news:1165418782.552172.169740@j44g2000cwa.googlegroups.com... > bonjour a tous, & a tous les pro bien sur > > es qu'il est possible ,qu...

double line spacing using excel 2000
I have a paragraph of writing, how do i get the text to be double line spaced? I am using excel 2000. Excel doesn't have a line spacing setting. You could add line breaks by pressing Alt+Enter at the end of a line, then another Alt+Enter to create a blank line. Dan wrote: > I have a paragraph of writing, how do i get the text to be double line > spaced? I am using excel 2000. -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html Does this aply to newer versions of excel? "Debra Dalgleish" wrote: > Excel doesn't have a...

Function Problem 12-07-07
Hello...ok I have a form with a button that I am trying to get to call on a function. I have been able to do this and the funtion processes but I keep getting an error. Now, the funtion works perfectly if I run it from the switchboard/menu, but when run from the form button I get this error: "The action or method requires a Table Name argument" Here is the code I have: Private Sub Update_All_Records_Click() On Error GoTo Update_All_Records_Click_Err DoCmd.OpenFunction Public_Income_Update_Step_1 Update_All_Records_Click_Exit: Exit Sub Update_All_Records_Click_Err: M...

Excel 95 to Excel 2003
Anyone know if it's possible to convert Excel 95 files to Excel 2003? If so, how. Thanks in advance Open the file in 2003 and SAVE as you would a file created in 2003. If not absolutely positive, save as a different name. -- Don Guillett SalesAid Software donaldb@281.com "Cooper" <kcooper2@austin.rr.com> wrote in message news:uqLpEuG4EHA.1292@TK2MSFTNGP10.phx.gbl... > Anyone know if it's possible to convert Excel 95 files to Excel 2003? If > so, how. > > Thanks in advance > > Open in XL 2003, when you close it, it should, ask you if you w...

Conversion Excel 97 to Excel 2003
Hi There, I would like to convert Excel 97 files to excel 2003 I m using Save AS, but little bit confuse what type I have to choose "Microsoft Office Excel workbood (*.xls)" or "Microsoft Excel 97 - Excel 2003 & 5.0/95 workbook (*.xls)". We will not use Office 97 anymore next few weeks. Thank for your prompt response. Wayne You shouldn't have to do anything. If you feel the need, just save as microsoft excel workbook.xls -- Don Guillett SalesAid Software donaldb@281.com "Wayne" <anonymous@discussions.microsoft.com> wrote in message news:8286...

Inner Borders in Excel 2007
Before in pre-Excel 2007 world, I used to be able to select a range of cells, click on a button to get vertical or horizontal boarders for the range selected. In Excel 2007 I can only apply outer boarders. Was this feature removed? I now have go to "format cells", then select the "borders" tab to do the same. Where did the buttons for inner vertical/horizontal boarders go? Thanks. louishong - Home ribbon > (Font group) drop down between Underline and Fill Color - Mike http://www.MikeMiddleton.com <louishong@lycos.com> wrote in message...

Convert excel to java
Hi does anybody know a way to convert an XL spreadhseet (with charts) to a fully interactive Java object?? I have tried exceleverywhere and xlsius, but no luck! Thanks in advance -- shnim1 ...

Importing Excel data into Access?
Can Excel data be imported into Access easily!? I know from Word table I can simply copy and paste but it is not that easy when doing from Excel to Access! I downloaded this manual from http://www.mousetraining.co.uk/training-manuals/Access2003Intro.pdf but couldn't find this topic If anyone knows please let me know! Cheers Raj Hello, there are plenty of sources. e.g.: http://office.microsoft.com/training/training.aspx?AssetID=RC102722321033 Stefan. "Rajeev Rawat" wrote: > Can Excel data be imported into Access easily!? I know from Word table &g...