Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default VBA code to copy and paste by values from one Excel workbook to another

Would anyone have a VBA function that copies everything that's on one
Excel workbook and paste just the values to another Excel workbook? I
just want to copy the values and not the references. It would be one
sheet to another sheet.

I've looked on the newsgroup, but am not able to find anything. Any
help is much appreciated.

Thanks,
Nhien

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default VBA code to copy and paste by values from one Excel workbook to another

Here's an example:

Sub test()
Dim wb As Workbook, ws As Worksheet

Set ws = ThisWorkbook.ActiveSheet
Set wb = Workbooks.Open("C:\filename.xls")

wb.Sheets(1).Range("A1").Copy
ws.Range("A1").PasteSpecial xlPasteValues

wb.Close Savechanges:=False
End Sub

--
Dan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default VBA code to copy and paste by values from one Excel workbook to another

On Aug 13, 5:37 pm, "Dan R." wrote:
Here's an example:

Sub test()
Dim wb As Workbook, ws As Worksheet

Set ws = ThisWorkbook.ActiveSheet
Set wb = Workbooks.Open("C:\filename.xls")

wb.Sheets(1).Range("A1").Copy
ws.Range("A1").PasteSpecial xlPasteValues

wb.Close Savechanges:=False
End Sub

--
Dan


How do I reference the Activesheet that I'm pasting to, if the sheet
is in another excel file? I'm calling the function from outside the 2
excel files. Do I open the workbook first. What is the code to make
that sheet active before I paste?

Nhien

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default VBA code to copy and paste by values from one Excel workbook to another

On Aug 14, 10:58 am, Nhien wrote:
On Aug 13, 5:37 pm, "Dan R." wrote:





Here's an example:


Sub test()
Dim wb As Workbook, ws As Worksheet


Set ws = ThisWorkbook.ActiveSheet
Set wb = Workbooks.Open("C:\filename.xls")


wb.Sheets(1).Range("A1").Copy
ws.Range("A1").PasteSpecial xlPasteValues


wb.Close Savechanges:=False
End Sub


--
Dan


How do I reference the Activesheet that I'm pasting to, if the sheet
is in another excel file? I'm calling the function from outside the 2
excel files. Do I open the workbook first. What is the code to make
that sheet active before Ipaste?

Nhien- Hide quoted text -

- Show quoted text -


I was able to get this working, but now whenever I close the workbook
that I copied from, it prompts me if I want to save the data in the
clipboard. How do I bypass the prompt if I am using the code above?

- Nhien

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default VBA code to copy and paste by values from one Excel workbook to another

Nhien,

Put this at the top of your code:

Application.DisplayAlerts = False


then put this at the bottom:

Application.DisplayAlerts = True

--
Dan



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default VBA code to copy and paste by values from one Excel workbook to another

On Aug 14, 5:47 pm, "Dan R." wrote:
Nhien,

Put this at the top of your code:

Application.DisplayAlerts = False

then put this at the bottom:

Application.DisplayAlerts = True

--
Dan


Thanks, I was able to get the DisplayAlerts to work. The only problem
I have now is after pasting the data, I want to remove the highlight
from the sheet. Here's my code. I get an error at
ws.Range("A1").Select. What am doing wrong?


Dim XL As Excel.Application
Dim wb As Workbook
Dim wb2 As Workbook
Dim ws As Worksheet


Set wb2 = Workbooks.Open(strMainFile)
Set ws = wb2.Sheets("POC_datasheet")
Set wb = Workbooks.Open(strWorkFile)
Set XL = wb2.Parent
XL.DisplayAlerts = False



wb.Sheets("POC_data").Range("A1:F65").Copy
ws.Range("A1:F65").PasteSpecial xlPasteValues
ws.Range("A1").Select

wb.Close SaveChanges:=True
wb2.Close SaveChanges:=True

-Nhien

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default VBA code to copy and paste by values from one Excel workbook to another

Nhien,

Put this before your select statement:

ws.Parent.Activate

--
Dan


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default VBA code to copy and paste by values from one Excel workbook to another

On Aug 15, 1:33 pm, "Dan R." wrote:
Nhien,

Put this before your select statement:

ws.Parent.Activate

--
Dan


It worked. Thanks Dan for all your help.

- Nhien

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Paste Values - Entire Workbook and Save Scott Campbell[_2_] Excel Discussion (Misc queries) 1 August 9th 07 07:53 PM
copy all and paste values for all sheets in a workbook cass calculator Excel Worksheet Functions 6 June 1st 07 02:58 PM
copy/paste values for all sheets in workbook cass calculator Excel Programming 2 May 31st 07 11:36 PM
code to FIND value, copy, paste values onto other sheet ufo_pilot Excel Programming 2 December 6th 05 04:14 PM
copy and paste using code from workbook to workbook bigdaddy3 Excel Discussion (Misc queries) 2 September 14th 05 11:06 AM


All times are GMT +1. The time now is 10:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"