Unselect Cells

B

bobwilson

I need to unselect the cells in the new worksheet (in new workbook) tha
I'm creating.

I can't seem to figure out how to unselect the cells from the ne
worksheet file that I'm creating. This is the part of my macro tha
creates a separate copy of my current activesheet. The Problem is whe
the Macro creates the new sheet it leaves all the cells selected s
when I open the file again they are all selected. How do I unselect th
sheet prior to the sheet saving?

Dim FileName As String
FileName = "C:\test5\" & Range("C105") & " " & Range("f105")

ActiveSheet.Copy
With ActiveWorkbook
.Sheets(1).Cells.Copy
.Sheets(1).Cells.PasteSpecial (xlPasteValues)
.SaveAs FileName
.Close
End Wit
 
G

Guest

Something needs to be selected. Try something like this...

With ActiveWorkbook
..Sheets(1).Cells.Copy
..Sheets(1).Cells.PasteSpecial (xlPasteValues)
..Sheets(1).Range("A1").Select
..SaveAs FileName
..Close
End With
 
G

Guest

Dim FileName As String
FileName = "C:\test5\" & Range("C105") & " " & Range("f105")

ActiveSheet.Copy
With ActiveWorkbook
.Sheets(1).Cells.Copy
.Sheets(1).Cells.PasteSpecial (xlPasteValues)
.Range("A1").Select
.SaveAs FileName
.Close
End With
 
P

paul.robinson

Hi
Park the cursor somewhere:

ActiveSheet.Copy
With ActiveWorkbook
With .Sheets(1)
.Cells.Copy
.Cells.PasteSpecial (xlPasteValues)
.Activate
.cells(1,1).Select
End With
..SaveAs FileName
..Close
End With

This is untested.

regards
Paul
 
G

Guest

typo:

ActiveSheet.Copy
With ActiveWorkbook
.Sheets(1).Cells.Copy
.Sheets(1).Cells.PasteSpecial (xlPasteValues)
.Sheets(1).Range("A1").Select
.SaveAs FileName
.Close
End With

or

ActiveSheet.Copy
With ActiveWorkbook.sheets(1)
.Cells.Copy
.Cells.PasteSpecial (xlPasteValues)
.Range("A1").Select
.Parent.SaveAs FileName
.Parent.Close SaveChanges:=False
End With
 
B

bobwilson

Thanks Tom - That works

What is the difference between the two types of code you provided?
assume it does the same thing. I'm just trying to better understan
VBA.

Bo
 
T

Tom Ogilvy

No real difference. The technical difference is how much of the reference I
put in the With statement and how much was repeated in the code between the
if statements. In your case, you had about as many lines referring to
Workbook actions as you did to sheet actions. So not much difference.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top