vba code for saving file

Hi,

I want to create a button that save (saveas) the workbook where the filename
should be the string thats in cell B2
Anyone?

txs


0
m.vink (13)
9/16/2003 1:26:18 PM
excel 39879 articles. 2 followers. Follow

2 Replies
773 Views

Similar Articles

[PageSpeed] 44

One way:

    Public Sub CommandButton1_Click()
        Const ERRSTR As String = "File not saved." & _
                vbNewLine & vbNewLine
        Dim fName As String
        On Error GoTo Handler
        With ActiveWorkbook
            fName = .Sheets("Sheet1").Range("B2").Text
            If Len(Trim(fName)) = 0 Then _
                Err.Raise 32769
            If Mid(fName, Len(fName) - 3, 1) <> "." Then _
                    fName = fName & ".xls"
            .SaveAs FileName:=fName
        End With
        Exit Sub
    Handler:
        If Err.Number = 32769 Then
            MsgBox ERRSTR & "Sheet1!B2 is empty"
        Else
            MsgBox ERRSTR & "Check Sheet1!B2 for valid filename."
        End If
    End Sub

You could add more error checking, of course. If you don't want to 
see the dialog asking if you want to overwrite an existing file, 
wrap the .SaveAs line with

    Application.DisplayAlerts = False
    .SaveAs FileName:=fName
    Application.DisplayAlerts = True


In article <OURabXFfDHA.3324@TK2MSFTNGP11.phx.gbl>,
 "Michael" <m.vink@nestas.nl> wrote:

> Hi,
> 
> I want to create a button that save (saveas) the workbook where the filename
> should be the string thats in cell B2
> Anyone?
> 
> txs
> 
>
0
jemcgimpsey (6723)
9/16/2003 1:46:19 PM
Txs m8,

You put me on the right track here, much appriciated!


Michael

"J.E. McGimpsey" <jemcgimpsey@mvps.org> schreef in bericht
news:jemcgimpsey-2BF4B8.07461916092003@msnews.microsoft.com...
> One way:
>
>     Public Sub CommandButton1_Click()
>         Const ERRSTR As String = "File not saved." & _
>                 vbNewLine & vbNewLine
>         Dim fName As String
>         On Error GoTo Handler
>         With ActiveWorkbook
>             fName = .Sheets("Sheet1").Range("B2").Text
>             If Len(Trim(fName)) = 0 Then _
>                 Err.Raise 32769
>             If Mid(fName, Len(fName) - 3, 1) <> "." Then _
>                     fName = fName & ".xls"
>             .SaveAs FileName:=fName
>         End With
>         Exit Sub
>     Handler:
>         If Err.Number = 32769 Then
>             MsgBox ERRSTR & "Sheet1!B2 is empty"
>         Else
>             MsgBox ERRSTR & "Check Sheet1!B2 for valid filename."
>         End If
>     End Sub
>
> You could add more error checking, of course. If you don't want to
> see the dialog asking if you want to overwrite an existing file,
> wrap the .SaveAs line with
>
>     Application.DisplayAlerts = False
>     .SaveAs FileName:=fName
>     Application.DisplayAlerts = True
>
>
> In article <OURabXFfDHA.3324@TK2MSFTNGP11.phx.gbl>,
>  "Michael" <m.vink@nestas.nl> wrote:
>
> > Hi,
> >
> > I want to create a button that save (saveas) the workbook where the
filename
> > should be the string thats in cell B2
> > Anyone?
> >
> > txs
> >
> >


0
m.vink (13)
9/17/2003 8:15:02 AM
Reply:

Similar Artilces:

Payout reason codes
Can someone point me to where in the database the payout reason codes are stored? thanks, Store Ops Manager, Database, Reason Codes, Type = Payout "Jason" wrote: > Can someone point me to where in the database the payout reason codes are > stored? > > thanks, Thanks. What I meant (and asked poorly) was if I wanted to design a custom report to show that info where would I need to look? Thanks, "Wendy_I" wrote: > Store Ops Manager, Database, Reason Codes, Type = Payout > > > > "Jason" wrote: > > > Can someo...

How to Use One PST file on Two Computers?
Hello: I have a desktop machine with a pst file in my Outlook 2003. I would like to copy this pst file to my laptop. How do I synchronize the same file on 2 machines so I won't get duplicate e-mails? I use one premium Yahoo e-mail account and several free Yahoo accounts with YahooPOPs.. Thanks in advance, Spudy Hi Spudy, it is not possible by default to share PST files. A list of a list of third-party synctools are also on this site: http://www.slipstick.com/outlook/sync.htm On the Microsoft Office Marketplace site is a list of third-party messaging tools: http://office.microsoft.com...

File location?
Where are the aspx files stored? http://site/subsite/list/defautl.aspx where would i find that? the reason i ask is when i go to export there are a couple of files that im told access denied. not sure why since im the admin on all levels. Thanks Justin Well, that really depends... mostly your stuff is stored in SQL, which means that its really data in a table cell. However, depending on whether a page has been customized or not it could be pointing to definition files that are stored on the Web Front End servers, and you really want to leave those alone. Furthermore, th...

How to Stop Worksheet_Change event from running during code execution
I'm sorry If I've asked this before but I can't find an answer to it. I have the following 2 events in a worksheet module.... Private Sub Worksheet_Change(ByVal Target As Excel.Range) Private Sub Worksheet_SelectionChange(ByVal Target As Range) I run some codes, either in UserForms or general procedures that make changes to this worksheet. Q. Is there a way to by-pass those two events somehow? As an example I have a uf that comes up if a cell is selected in that sheet. So I need those worksheet_Change events to work at that point. But then, the uf does some stuff like inputing ...

encoding wmv file
hello I have a sample application developed in MFC dialog based project using directx sdk 9. the sample captures video from a webcam and saves it to a wmv file now i have to put that video into streaming server. i beleive that i will have to encode the wmv file using some codecs to put it into streaming server. i want to do the capturing and encoding simultaneously. below is a portion of my code to capture video // capture video pBuilder->RenderStream(&PIN_CATEGORY_CAPTURE, // Pin category &MEDIATYPE_Video, // Media type p...

VBA code to say Yes or No if any VBA code is present in ActiveWork
Using XL 2003 & 97 Would like hit Ctrl+Shift+V and have an answer either yes or no as to the presence of Any VBA code in the Active Workbook. I do know that about the VBA editor/Explorer or to press the Run Macro button and get a list from various sources . I would like to stay at the keyboard and process a series of macros including one to let me know if I even need to evoke the VBA explorer. TIA Dennis There is no bootstrap macro to tell you whether you have macros or not. If there were there would be no limit to virus writers. --- HTH, David McRitchie, Microsoft MVP - Excel ...

Sort several workbooks using code
I am looking to run code that will sort several workbooks even when they are closed. The code would be executed via a master workbook which will also be sorted. Is this possible? I'm not aware of sorting records in a CLOSED workbook, but what you can do is this. Create some button on the master workbook and let it open the other workbook, sort the other workbook and close the other workbook. Accompanied with Application.ScreenUpdating (but also depending on the amount of records) you will hardly notice the sorting actions. Does this help ? -- Regards; Mark ...

Print, Merged Cells, and VBA
Hello I'm looking for a code that will help me with a print job for a worksheet. There are a lot of merged cells and a lot of "IF"s to be used in the VBA for range selection. Thanks in advance, Sarr ...

Use VBA to update Access table or Query from Excel
Can I use VBA to update Access table or Query from Excel? Thanks in advance Hi Leungkong, > Can I use VBA to update Access table or Query from Excel? Of course, using ADO or DAO. See: http://www.erlandsendata.no/english/index.php?d=envbadacexportado Regards, Jan Karel Pieterse Excel MVP http://www.jkp-ads.com Hi Jan, Thanks. I think ADO is what I want. But I am not only want to export from excel to access. I want to edit some data in access table. For example, Access has a table "ProductList" I want to use Excel to call the product by "Pro...

Backup cannot copy .pst files
When I exit Outlook and click on Save Backup. I get the error "Cannot copy Outlook: The process cannot access the file beause another process has locked a portion of the file" Please advise with how to fix this problem. ...

Missing DLL file prevents me using PST Files?
Hello - I posted on here a while ago asking for help as following a company merger I cannot use PST files in Outlook 2000 (Windows NT machine). I have been told that work have removed a DLL file which is causing this. Do any of you have experience of this? If so any idea what DLL file I need to add back in? Many thanks, Carl. Do you mean that the corporate IT removed the DLL so you can't use PSTs? Do they have a good reason for this? "Carl Jarvis" <carljarvis@nothankyouforthespammister.co.uk> wrote in message news:1125040515.4863.0@nnrp-t71-03.news.uk.clara.ne...

VBA and Scheduled task in Outlook
Hi, how can I: a) pull the query from somewhere and send it by e-mail automatically. E.g. I want to take a temperature table from http://www.wunderground.com/history/airport/EHAM/2009/7/10/DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA where 2009/7/10 is the date of yesterday put it into an e-mail and send it automatically each day at 8 o'clock? b) if this is not possible, how can I send an e-mail with the attachment c:\Documents\query20090710.xls each day at 8 o'clock? my boss wants this automatized, I know how to write the VBA code for Excel, but don'...

vba select field
Hi, having a button on a form, is it possible to select only some fields (all from the same table) of the current record instead of all fields? I've tried this code: RunCommand acCmdSelectRecord RunCommand acCmdCopy Forse dipende dei dati nel record. but it selects ALL fields in the form. Thank you. Remigio hi, On 10.04.2010 18:01, remigio wrote: > having a button on a form, is it possible to select only some fields > (all from the same table) of the current record instead of all fields? > I've tried this code: > > RunCommand acCmdSelectRecord &...

Restoring Exchange Store files to a new server
We had a major system crash this week but I was able to grab the entire exchsrv directory from the server. What files do I need to copy to the new server to get all of my exchange mail/public folders/etc loaded on the new server? Thanks, CJ What version of Exchange? -- Ed Crowley MVP - Exchange "Protecting the world from PSTs and brick backups!" "Curious Joe" <joebob.johnson@gmail.com> wrote in message news:1160176822.798021.310710@m73g2000cwd.googlegroups.com... > We had a major system crash this week but I was able to grab the entire > exchsrv director...

How get rid of reveal codes?
How get rid of reveal codes? the symbols are all over my document!! How do I get rid of them?? Try:- ALT + F9 If my comments have helped please hit Yes. Thanks. "Christa" wrote: > How get rid of reveal codes? the symbols are all over my document!! How do > I get rid of them?? Ctrl+* or Ctrl+Shift+8. See http://word.mvps.org/FAQs/Formatting/NonPrintChars.htm -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org "Christa" <Christa@discussions.microsoft.com> wrote in mes...

VLOOKUP in VBA
On the worksheet I can insert in a cell =VLOOKUP(C5, Hobokee.xls!AcsLow, 2) and it works perfectly, looks up the value in column 2 of the range named AcsLow in the same workbook. But elswhere I want in a macro to lookup the same table and assign the result to a variable BalAmt. BalAmt = VLOOKUP(AccNum, Hobokee.xls!AcsLow, 2) does not work. It gives a function not defined error on Hobokee. If instead of Hobokee I put Workbooks("Hobokee"), it gives function not defined error for VLOOKUP which it changes to VLookup. I have been overVLOOKUP in the Help file and see nothing wrong. W...

xls file failure
A log.xls file was saved to the desktop in win'98se. On double clicking the file, an 'i' error is generated indicating that the 'file cannot be accessed. The file may be read only.'. The file attribute was archive and changing it to anything else, didn't help. Copy-paste and rename also didn't help. Is this file unrecoverable? Thanks. Len Delete all files in your C:\windows\temp directory -- files and directories that is, reboot and try again "lendapilot" <lendapilot@discussions.microsoft.com> wrote in message news:FE94FAF2-AF35-44B8-91F4-B97...

Files Ofiice 2003 using Vista operating system
Where are my pab or pst files in Microsoft Office 2003 when using Micrsoft Vista Home Premium? Or do they have another name or location Hondaman95 <Hondaman95@discussions.microsoft.com> wrote: > Where are my pab or pst files in Microsoft Office 2003 when using > Micrsoft Vista Home Premium? Or do they have another name or location The PAB is obsolete and you shouldn't be using one. The PST's default location is %LocalAppData%\Microsoft\Outlook -- Brian Tillman [MVP-Outlook] "Brian Tillman" wrote: > Hondaman95 <Hondaman95@discussions.microsoft....

Excel VBA/Macro programming for beginners
Hi all, I know a bit VB 6.0 programming. Will it help me to write exce vba/macro(same thing?).can anybody help me by providing some fre websites where i can have informations/codes for VBA/macro. Please tell me how could i make a *command Button * in a cell in th excel sheet -- sdebu_200 ----------------------------------------------------------------------- sdebu_2000's Profile: http://www.officehelp.in/member.php?userid=430 View this thread: http://www.officehelp.in/showthread.php?t=118812 Posted from - http://www.officehelp.i Try David McRitchie's "getting started with mac...

Printing a merged to file
Hello, I have searched for this topic but did not find another similar question. I am merging mail addresses to a four up postcard form. If I merge to a document and try to print it, I either get four copies of the same address on each sheet or one copy in the middle of the four up form. If I merge to the printer, I get four addresses per sheet in the right place. That would be fine, but some of the addresses are long enough that they wrap and they wrap in a place where the program decides. Foe example: Johnathan Quixley & Jane Elizabeth Doe may wrap to be "Johnathan Quixley & J...

Turn pc speaker on/off with vba code
Is this possible? Thanks I found something here on how to do it withVBScript. You can probably modify it to work in VBA http://www.pcreview.co.uk/forums/thread-1468591.php -- HTH, Barb Reinhardt "David" wrote: > Is this possible? > Thanks Thanks Barb I'll have a go (I need to improve my web searching skills) "Barb Reinhardt" wrote: > I found something here on how to do it withVBScript. You can probably modify > it to work in VBA > > http://www.pcreview.co.uk/forums/thread-1468591.php > -- > HTH, > ...

Loading a Form from VBA
Hi all, I'd like a module to open and load a form in my Access 2003 database... How can I do this? Use the OpenForm method. Look in the Help file for details. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Mike" <michael.leon.schwartz@gmail.com> wrote in message news:1184770076.109526.207900@o11g2000prd.googlegroups.com... > Hi all, I'd like a module to open and load a form in my Access 2003 > database... How can I do this? > On Jul 18, 10:58 am, "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com&g...

File> ... Can I see more file names?
When I click on File I see (below the list of available options) four previously saved xls files. How do I see more , say the last 10 saved files? <Tools> <Options> <General> tab, And increase to 9 (max) the number of entries in the "Recently Used File box. -- HTH, RD ============================================== Please keep all correspondence within the Group, so all may benefit! ============================================== "SouthAfricanStan" <me@there> wrote in message news:uAdxTx8FFHA.1260@TK2MSFTNGP12.phx.gbl... When I click on File I see...

Excel and VBA
I am very interested in learning more about using VBA in office, especially Excel. Can you post some resources (online, books, etc) that can be used to help learn about using Visual Basic in office. Thanks! Here's a good place to start: http://www.contextures.com/xlbooks.html Does that help? *********** Regards, Ron XL2002, WinXP "Bob Sinclair" wrote: > I am very interested in learning more about using VBA in office, especially > Excel. Can you post some resources (online, books, etc) that can be used to > help learn about using Visual Basic in office. >...

VBA Customization
Is there a way to get the name of the current company through VBA in Great Plains 8.0? Thanks for all your help. open GreatPlains. Add the current window, it will add the Toolbar then add fields choose the company name on the top left after the user id. >-----Original Message----- >Is there a way to get the name of the current company through VBA in Great >Plains 8.0? > >Thanks for all your help. > > > >. > Thanks. I tried, but I couldn't add company name to the field list. It opens up the login screen instead. Any thoughts? Thanks again. "ger...