Try To Close Then Delete Using Code
Mar 30, 2007
I can save and create pdf, I just need help deleting the .xls file.
Her is code I have:
ActiveWorkbook.Save
Path = "C:Emailed Proposals"
On Error Resume Next
ActiveWorkbook.SaveAs Filename:= _
Path & Range("C6").Value & Range("O3").Value & ".xls"
On Error GoTo 0
Application.ActivePrinter = "PrimoPDF on Ne00:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"PrimoPDF on Ne00:", Collate:=True
Application.ActivePrinter = "EPSON Stylus C86 Series on Ne02:"
I need to keep the newly created .pdf and delete the created/saved .xls file, I just can't ssem to figure out what I need to write in code.
View 9 Replies
ADVERTISEMENT
May 1, 2008
I'm working on a time sheet, and to make it easier to enter time i created a macro that sets the auto correct to correct a "." to a ":", but when the workbook closes i want to run a macro that deletes the auto correct rule.
View 13 Replies
View Related
Jul 11, 2009
I know this is the code to close a workbook
View 5 Replies
View Related
Sep 29, 2008
I have a template where users provide input in specified fields. Upon completion, pressing a macro button emails the file to administrator.
find out a code that once email is sent, perform following actions simultaneously;
Pop up message to appear as “Message Sent – Do you want to process another request?
If reply is Yes, the sheet is refreshed
If reply is No, File is closed without Saving
View 9 Replies
View Related
Jan 29, 2007
The code below works perfectly when run from a macro button on a worksheet or when initiated using the VBA run option in the VBA editor but it does not run when run from a command button on a userform. The code is
Sub closer()
Dim bCancel As Boolean
Do Until bCancel = True
bCancel = Application.Dialogs(xlDialogSaveAs).Show
If bCancel = False Then MsgBox "Sorry, cannot Cancel", vbCritical
Loop
ActiveWorkbook.Close SaveChanges:=False
End Sub
When I run the code from a command button on my userform the error message I get is: 'Run-Time error 1004 Document not saved' and the line of code that it continually gets stuck on is: bCancel = Application.Dialogs(xlDialogSaveAs).Show
View 2 Replies
View Related
Nov 2, 2007
I have a piece code that allows the user to pick a file from a folder on my C:. It then copies a range of data into the original workbook that the macro was run. I would like to close the other file down automatically which shouldn't be that hard but I can't work out how to do it.
View 9 Replies
View Related
Jun 26, 2009
I have a macro that runs and I want it to close excel when it is done. The best I can do is to get it to close the worksheet and workbook.
What is the code to make excel completely close?
View 9 Replies
View Related
Sep 7, 2009
I tried to use Workbooks("Inactivebookname.xlsm").Close False
and many variations thereof, but I simply cannot close this workbook when currently another workbook is active.
I have no problem in closing an active workbook with
ActiveWorkbook.Close
View 9 Replies
View Related
Dec 29, 2006
I am trying to inch my way forward to writing a macro that will read in an external CSV file into a sheet (my next task will be to spread the date between multiple sheets based on regions). My first attempt at code is the following
Sub read_csv()
Dim strLine As String
Dim i As Integer
Dim filename As String
Dim ans As String
filename = "C:Documents and SettingsMichaelMina dokumentMina datakällorD123905.csv"
Open filename For Input As #1
i = 1
While Not EOF(1) And i < 10
Line Input #1, sLine
ans = MsgBox(sLine, vbOK, "hello there")
i = i + 1
Wend
' Close filename
End Sub
A couple of problems arise. When I debug the code, if I remove the comment on the close filename, the debugger complains with error 13 (incompatible types). If I comment the line and try and run the code twice in a row, I get a complaint about error 55 - file already open. I'm guessing that the close filename is the correct syntax - if it isn't, what should it be??
View 5 Replies
View Related
Mar 23, 2009
macro is not exiting from print preview mode. Need the VBA code so it can close the print preview mode (preferably not "private sub" code)
View 2 Replies
View Related
Jan 17, 2013
I have a workbook which should only be used between certain dates
In this example between 3rd March 2013 and the 1st March 2014
Would it be possible that if the user opens the workbook outside of this date range an error message could appear then the workbook would then close ?
View 6 Replies
View Related
Sep 11, 2013
I have a list of 10 shops as a list box named lstitems i need the user to click one of the 10 shops and when they click the selected shop it tells the name they selected. then i require a Quit button that transfers the selected Shop to cell D3 & then closes the userform, but if they do not pick a shop it will ask them to pick one before it closes. so they must select or it will not close.
View 9 Replies
View Related
Jul 31, 2007
I want code to:
Open EstimatingSheet.xls
SaveAs current workbook as Range B13 &".xls"
Open EstimatingSheet.xls workbook from somewhere on C:
Then close the one with B13.xls
View 9 Replies
View Related
Feb 16, 2009
We're using XP Pro using Excel 07
The background is there are about 40 people who use a Excel based program that contains a pivot and a bunch of other tools that they use on a regular basis, this set of tools has a version number. In this excel workbook, it has a function that looks on the network drive that we have and checks the local version vs the version on our network drive, if its wrong, then the user gets a popup stating your tools are out of date, would you like to update, then they click yes and I have these lines of code
Public Function GetNewTools()
Dim MyFullName As String
'Turn off alerts
Application.DisplayAlerts = False
'Open the new version of tools
Workbooks.Open Filename:= _
"Network DriveUpdate.xlsm"
End Function
The update file has this code that executes on fileopen in the thisworkbook section by calling the following sub
The main issue we're running into is near the very end, the code never makes it to "TEST 2". After the first workbooks close, the code just stops running. No crashes, errors, freezes, anything. It just stops running and never makes it to the second msg box.
View 9 Replies
View Related
May 15, 2009
I have two procedures in two different access forms. First procedure executes fine. It ends up with creating a Table1 by importing the data successfully from the Excel file. But after that later when I call procedure 2, it throws the below error when it is trying to import the data in to Table2. I think the Excel "Test.xls" did not save properly and close in the Procedure 1. I could see some Excel thread running in the Task Manager. How can I handle this. Please advice. Your expertise help will be truly appreciated. I am absolutely new to this VB-Access code world.
Error: "'MySheet2$'is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long." ....
View 9 Replies
View Related
Nov 21, 2006
I have a workbook which includes a simple set of options on closing such as selecting the front sheet, restoring scrollbars and saving the workbook. To avoid problems with subscripts out of range I am using the ThisWorkbook statement to close the workbook.
This works fine and causes the workbook to close when close is clicked on any excel window. The problem is that excel falls over when it tries to resume closing the other workbooks. I am given (ironically) an error saying "excel has encountered a problem and needs to close". Does anyone know how to work around this?
My code is below:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call Toolbars9(True)
With ActiveWindow
.DisplayHorizontalScrollBar = True
.DisplayWorkbookTabs = True
End With
View 8 Replies
View Related
Apr 23, 2008
I have a spreadsheet with a number of fields on it which must be filled in before the file can be saved, and if the user attempts to close the spreadsheet without filling in the required fields, I want a message box to appear asking for confirmation that the user wishes to quit, if yes, the sheet exits, if no, the sheet remains open
View 2 Replies
View Related
Oct 22, 2009
When I close my worksheet excel asks me if I wish to save the file one last time, if I click 'yes' I would like some more code to be executed and then have the spreadsheet save itself and close definitively, how can this be done using vba?
View 9 Replies
View Related
Jul 24, 2009
I'm trying to write a VBA script which will delete all rows in my Excel spreadsheet where Column I (which contains a status code) does not contain the word "Completed".
At the moment, I'm doing this the other way round: my script is able to search for entries in Column I which contain the status codes "Pending", "Awaiting Authorisation", "In Progress" etc and delete them. The idea is that when all those rows are deleted, I'll only be left with rows which have a status of "Completed". This works fine at the moment. However, the concern is that if a brand new status code is added to the data file, my script would be unable to pick it up and delete it. This is a small sample of the code I'm currently using (which deletes all the rows with statuses other than Completed):
View 4 Replies
View Related
Mar 22, 2012
I am using Excel 2003.
It’s been working perfectly up until around an hour ago. However, now when I close Excel, I get compile errors.
These compile errors seem to be because Excel is trying to access controls in the workbook after it has closed. Since the workbook is closed, VBA can no longer ‘see’ the controls, and therefore it thows up errors.
I’m also getting a similar error on a Worksheets("DataExplorer").unprotect line, which seems to be because the worksheet isn’t there after closing.
These errors only occur when I close the whole excel application using the big cross in the top right. If I just close the workbook (using the smaller cross just below the big cross in the top right of excel), it doesn’t throw up these errors.
Just to clarify: all of the code runs perfectly when Excel is open. The errors are being thrown up for lines of code which run without problem until Excel is closed.
View 9 Replies
View Related
Nov 2, 2009
Each of the worksheets in my model use A1 as a control cell for any errors and inconsistencies. My aim is to disable save and close commands in case A1 is not equal to 0 in any of the worksheets.
The code I currently use for that purpose is as follows.
View 2 Replies
View Related
Oct 11, 2006
I need to know the command to close a workbook. I have used the information found here: http://www.ozgrid.com/VBA/userform-close.htm to disable closing the workbook via the upper right "X", but I need a button that, when clicked, simply closes the workbook instead.
View 2 Replies
View Related
Apr 26, 2009
I'm wondering if anyone has code to delete a row on all but the first 5 sheets in a workbook? I'm using Excel 2007.
View 2 Replies
View Related
Mar 27, 2014
I would like to add 2 buttons to each page. One button to add a row at the bottom of the table while keeping all of the same formatting and another button to Delete a selected row from the table. So that if there is more assignments than allowed in the current table, a row could easily be added.
I would think that the code for the class sheets would all be the same.
The other obstacle I thought about is possible making a button on the Summary page that would add another sheet, call it Class and whatever number comes next and also add it to the summary table with the same formatting (including the hyperlink that's in the Classes column where it will take you to the Class sheet that you want to drill down to).
I have attached the file. If the summary sheet is took much work it's not a big deal, I would be fine with just being able to have 2 buttons on the class sheets that allowed them to add and remove and such.
I would also like to contribute. I know a decent amount about SQL and SSRS/SSIS Reporting services.
I also need it to be able to unprotect my worksheet and then protect it back, Since I will only want them to be able to type in the areas I specify. I also moved the summary at the bottom of each class sheet to the right side at the top so its easier for them to view.
View 5 Replies
View Related
Jan 22, 2009
I have an excel file that i need to delete some empty rows in the file. it looks like this: I have to delete THE EMPTY ROW above each custom table, and leave everything else as it is.
empty row
custom table
data
data
data
empty row
custom table
data
data
data
data
empty row
custom table
data
data
View 11 Replies
View Related
Mar 16, 2009
How do you delete a single sheet from a workbook by name? I assumed something like this, but it doesn't work
View 2 Replies
View Related
Mar 25, 2009
VB Code to delete a file. I have the following code that creates a file.
View 4 Replies
View Related
May 12, 2009
Can anyone help me here? I'm in need of a VB Code.
I need the code to do the following:
If any cell in column "L" = "n/a" then delete that corresponding row.
IE - Cell L23 = n/a so then delete row 23.
View 11 Replies
View Related
Jun 16, 2009
See attached workbook. If you hit the Export button (runs Export Macro), it creates a new workbook. Most of what I have in the code works fine except the following bit:
View 2 Replies
View Related
Jan 19, 2010
Can someone help me out with this script?.
I keep getting "Subscript Out of Range Error"
I'm trying to delete all the code on sheets(1) of the active workbook.
View 8 Replies
View Related