closing excel without saving - not working properly

smakatura

Board Regular
Joined
May 27, 2011
Messages
141
I have two documents. sourcedocument and fulldatafilename. I pull data from the fulldatafilename, paste into sourcedocument and then close source document.

I can open fulldatafilename and work with it and even switch between the sourcedocument. but I can not seem to close the fulldatafilename. and I have not 'undefined' fulledatafilename.

I am using similar coding to below. (I have simplified it to the basic code for easier reading). assume I am runnig the macro from sourcedocument

HTML:
    Dim fulldatafilename As String
    Dim sourcedocument As String
 
    fulldatafilename = "data file 089-2.xlsx"
    sourcedocument = "JOBS Weekly Template.xlsm"
 
    Workbooks.Open Filename:=fulldatafilename     'this works
          '******code for copying data from fulldata filename here
    Windows(sourcedocument).Activate     'this works
          '******code for pasting data from fulldata filename here
    ActiveWorkbook.Save    'this properly saves the source document
 
    Workbooks(fulldatafilename).Close False     ' this is the part that is not working.

not sure why not working bc Workbooks(fulldatafilename).Close False or similar code works in other macros.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
If you do not want or need to save "fulldatafilename" you could try adding one line before your close action:

Code:
Workbooks(fulldatafilename).saved

This tells Excel that it's already been saved and no save before close check is required.
 
Upvote 0
that is correct, I do not wish to save the changes made to fulldatafilename...but willl the extra saved statement allow it save...the macro gets stuck on the code and will not even ask me if I want to save.
 
Upvote 0
I noticed something else when looking at this again. Your code says
workbooks(...).close false

Try getting rid of that. And if that doesnt work switching it to true.
 
Upvote 0
if I change the false to true, it will save the changes made. I don't want to save my changes.

I tried
HTML:
Workbooks(fulldatafilename).saved
and it did not work. it did not like the command
 
Upvote 0
I figured out why it was not working. fulldatafilename included the c: portions of the file....so my full definitions were(which I did not include originally and therefore made the question incomplete)

HTML:
    Dim rptdate As String
    Dim datafilename As String
    Dim datafilelocation As String
    Dim fulldatafilename As String
   
       
    datafilelocation = "C:\Users\smakatura\Documents\call report\Call Reports\JOBS Center Call Log Master\"
    datafilename = "JOBS Center Call Log Master "
    rptdate = "09-26-11"
    fulldatafilename = datafilelocation & datafilename & rptdate & ".xlsx"


once I changed the command from
HTML:
Workbooks(fulldatafilename).Close False
to
HTML:
Workbooks(datafilename & rptdate & ".xlsx").Close SaveChanges:=False

it worked. trouble was I was trying to close with the path also ...not just the open file name.

thank you for everyones help
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,039
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top