Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(a) Close Inactive Workbook (b) Insert a file name to a column

Status
Not open for further replies.

Suggie

Technical User
Aug 8, 2003
116
EU
Hello,
Hope someone can help with my first question, I've searched the threads and cannot find an answere

Problem A :
I am trying to close all inactive workbooks and using the following code :

Public Sub CloseAllInactive()

Dim Wb As Workbook
Dim AWb As String
AWb = ActiveWorkbook.Name

SaveAll
For Each Wb In Workbooks
If Wb.Name <> AWb Then
Wb.Close savechanges:=True
End If
Next Wb
Application.StatusBar = &quot;All Workbooks Closed.&quot;

End Sub

The issue is that I am first copying data from file x and pasting file y (file y is constant and will always be called &quot;Consolidated Logs&quot;) and then trying to close file x with the above code, but I get a message asking if I want to save to the clipboard? If I chose Y, the system hangs and if I chose N, the details don't paste! Any ideas?? I just want to close file x after pasting to file y and leave file y open.

Second part of my question is : how to I insert the file name of an open workbook into the worksheet, cell A:1

Many thanks in advance
Mark
 
Sorry I can't help with the first bit, but here's the code to insert the workbook name into cell A1:

a$ = ActiveWorkbook.Name
Range(&quot;a1&quot;).Value = a$

Regards,

Ian
 
Or even easier....

Range(&quot;A1&quot;).Value = ActiveWorkbook.Name
 
Thanks Ian, this helps.

Can anyone figure out the first part of my Question?

Thanks again and enjoy the weekend.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top