Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Macro to copy from another workbook

I have created a macro to copy from another workbook, the thing is that I am
trying to get it copy from a CSV workbook into an Excel workbook and for some
reason when it does copy, it only says #REF, which would mean it is copying
using a formula, but I'm not using a formula on the sheet, the macro can be
seen below, its basically a two part module:


Module 1:


Sub File_In_Local_Folder()
Application.ScreenUpdating = False
On Error Resume Next

'Call the macro GetRange
GetRange "path to file", "name of file in CSV format", "Sheet1",
"A1:Q1204", _
Sheets("Sheet3").Range("H3")

On Error GoTo 0
Application.ScreenUpdating = True
End Sub


Module 2:

Sub GetRange(FilePath As String, FileName As String, SheetName As String, _
SourceRange As String, DestRange As Range)

Dim Start

'Go to the destination range
Application.Goto DestRange

'Resize the DestRange to the same size as the SourceRange
Set DestRange = DestRange.Resize(Range(SourceRange).Rows.Count, _
Range(SourceRange).Columns.Count)

'Add formula links to the closed file
With DestRange
.FormulaArray = "='" & FilePath & "/[" & FileName & "]" & SheetName _
& "'!" & SourceRange

'Wait
Start = Timer
Do While Timer < Start + 1
DoEvents
Loop

'Make values from the formulas
.Copy
.PasteSpecial xlPasteValues
.Cells(4).Select
Application.CutCopyMode = False
End With
End Sub


In addition is there anyway I can make it so that when it searches within
the folder, it would search for the latest csv file within the folder, the
most recently modified,


Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 245
Default Macro to copy from another workbook

Have a look here

http://www.rondebruin.nl/copy7.htm

"drinese18" wrote:

I have created a macro to copy from another workbook, the thing is that I am
trying to get it copy from a CSV workbook into an Excel workbook and for some
reason when it does copy, it only says #REF, which would mean it is copying
using a formula, but I'm not using a formula on the sheet, the macro can be
seen below, its basically a two part module:


Module 1:


Sub File_In_Local_Folder()
Application.ScreenUpdating = False
On Error Resume Next

'Call the macro GetRange
GetRange "path to file", "name of file in CSV format", "Sheet1",
"A1:Q1204", _
Sheets("Sheet3").Range("H3")

On Error GoTo 0
Application.ScreenUpdating = True
End Sub


Module 2:

Sub GetRange(FilePath As String, FileName As String, SheetName As String, _
SourceRange As String, DestRange As Range)

Dim Start

'Go to the destination range
Application.Goto DestRange

'Resize the DestRange to the same size as the SourceRange
Set DestRange = DestRange.Resize(Range(SourceRange).Rows.Count, _
Range(SourceRange).Columns.Count)

'Add formula links to the closed file
With DestRange
.FormulaArray = "='" & FilePath & "/[" & FileName & "]" & SheetName _
& "'!" & SourceRange

'Wait
Start = Timer
Do While Timer < Start + 1
DoEvents
Loop

'Make values from the formulas
.Copy
.PasteSpecial xlPasteValues
.Cells(4).Select
Application.CutCopyMode = False
End With
End Sub


In addition is there anyway I can make it so that when it searches within
the folder, it would search for the latest csv file within the folder, the
most recently modified,


Thanks


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
Macro to copy an image (or picture) from one workbook to a new sheetin another workbook Ruchir Excel Worksheet Functions 1 July 25th 08 07:29 AM
Copy workbook, don't copy macro CongroGrey Excel Discussion (Misc queries) 1 June 13th 08 04:56 PM
How can I copy a macro into another workbook? jbeene New Users to Excel 4 March 15th 07 06:53 PM
Copy macro to another workbook FTM Excel Discussion (Misc queries) 4 September 21st 06 08:48 PM
Need a macro to copy a range in one workbook and paste into another workbook Paul Excel Programming 8 July 1st 04 07:42 AM


All times are GMT +1. The time now is 08:17 AM.

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

About Us

"It's about Microsoft Excel"