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


I have data in "Mailer List.xls"
On the sheet labeled "mor01001" of this workbook I need to bring in th
data cells
A2:A4001, B2:B4001, C2:C4001, D2:D4001, E2:E4001 F2:F4001 G2:G4001


I need a macro that I can run once a month to import this data int
"Direct Mailer Template.xls"
It would need to be imported to the sheet labeled "Helper Sheet" in th
corresponding cells
A2:A4001, B2:B4001, C2:C4001, D2:D4001, E2:E4001 F2:F4001 G2:G400

--
jermsalerm
-----------------------------------------------------------------------
jermsalerms's Profile: http://www.excelforum.com/member.php...fo&userid=3016
View this thread: http://www.excelforum.com/showthread.php?threadid=49854

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Macro to import from one closed workbook

Sub c()
srcpath = "C:\SFADB"
srcbook = "random.xls"
srcsheet = "R1"

aydes = Array("c1:c6", "d1:d6", "e1:e6")
aysource = Array("$A$5:$A$10", "$b$5:$b$10", "$b$5:$b$10")

Set wsdes = Sheet

For i = LBound(aydes) To UBound(aydes)
With wsdes.Range(aydes(i))
.FormulaArray = "='" & srcpath & "\[" & srcbook & "]" & srcsheet &
"'!" & aysource(i)
.Copy
.PasteSpecial xlPasteValues
End With
Next i
Application.CutCopyMode = False
Set wsdes = Nothing
End Sub

edit to fit

- voodooJoe

"jermsalerms"
wrote in message
...

I have data in "Mailer List.xls"
On the sheet labeled "mor01001" of this workbook I need to bring in the
data cells
A2:A4001, B2:B4001, C2:C4001, D2:D4001, E2:E4001 F2:F4001 G2:G4001


I need a macro that I can run once a month to import this data into
"Direct Mailer Template.xls"
It would need to be imported to the sheet labeled "Helper Sheet" in the
corresponding cells
A2:A4001, B2:B4001, C2:C4001, D2:D4001, E2:E4001 F2:F4001 G2:G4001


--
jermsalerms
------------------------------------------------------------------------
jermsalerms's Profile:
http://www.excelforum.com/member.php...o&userid=30167
View this thread: http://www.excelforum.com/showthread...hreadid=498548



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default Macro to import from one closed workbook

The following first code below will work when your source is a single
contiguous range.
However, since your Source has several areas you will need to add a loop to
copy one area at a time. See bottom:

Option Explicit

Sub CopyFromTest1()

Dim sFile As String
Dim Wbk As Workbook
Dim Source As Range
Dim Dest As Range


On Error Resume Next
Set Wbk = Workbooks("Test1")

If Wbk Is Nothing Then 'its not open
sFile = ThisWorkbook.Path & "\Test1.xls"
Set Wbk = Workbooks.Open(sFile)
End If
If Wbk Is Nothing Then
MsgBox "Unable to find the file: " & sFile, vbOKOnly, "ERROR"
Exit Sub
End If

Set Source = Wbk.Sheets(1).Range("A1:A2")
Set Dest = ThisWorkbook.Sheets(1).Range("A1:A2")
Source.Copy Dest
Wbk.Close False

End Sub


Redefine the Source and Dest to include all of the areas, keeping them in
the same order.
Add this variable: dim i as integer

Then insert or change the copy part to:
For i=1 to Source.Areas.Count
Source.Area(i).Copy Dest.Area(i)
i=i+1
Next i

"jermsalerms" wrote:


I have data in "Mailer List.xls"
On the sheet labeled "mor01001" of this workbook I need to bring in the
data cells
A2:A4001, B2:B4001, C2:C4001, D2:D4001, E2:E4001 F2:F4001 G2:G4001


I need a macro that I can run once a month to import this data into
"Direct Mailer Template.xls"
It would need to be imported to the sheet labeled "Helper Sheet" in the
corresponding cells
A2:A4001, B2:B4001, C2:C4001, D2:D4001, E2:E4001 F2:F4001 G2:G4001


--
jermsalerms
------------------------------------------------------------------------
jermsalerms's Profile: http://www.excelforum.com/member.php...o&userid=30167
View this thread: http://www.excelforum.com/showthread...hreadid=498548


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Macro to import from one closed workbook

Hi jermsalerms,

The ranges you've given for the copy and paste (A2:A4001, B2:B4001,
C2:C4001, D2:D4001, E2:E4001, F2:F4001, G2:G4001) corresponds with the single
range A2:G4001. In which case a single copy-paste is all that's required...

Sub ImportData()
Application.ScreenUpdating = False
On Error Resume Next '< error = Mailer List.xls is already open
Workbooks.Open ("C:\Windows\Desktop\Mailer List.xls")
Sheets("mor01001").Range("A2:G4001").Copy _
Destination:=ThisWorkbook.Sheets("Helper Sheet").Range("A2")
Workbooks("Mailer List.xls").Close False
Application.ScreenUpdating = True
End Sub

HTH,
John
--
The major part of getting the right answer lies in asking the right
question...


"jermsalerms" wrote:


I have data in "Mailer List.xls"
On the sheet labeled "mor01001" of this workbook I need to bring in the
data cells
A2:A4001, B2:B4001, C2:C4001, D2:D4001, E2:E4001 F2:F4001 G2:G4001


I need a macro that I can run once a month to import this data into
"Direct Mailer Template.xls"
It would need to be imported to the sheet labeled "Helper Sheet" in the
corresponding cells
A2:A4001, B2:B4001, C2:C4001, D2:D4001, E2:E4001 F2:F4001 G2:G4001


--
jermsalerms
------------------------------------------------------------------------
jermsalerms's Profile: http://www.excelforum.com/member.php...o&userid=30167
View this thread: http://www.excelforum.com/showthread...hreadid=498548


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Macro to import from one closed workbook

I wasn't as observant as John to see that it really is only one range, that
makes it a lot easier.
but there really isn't a need to open the source workbook to get the
values - use a link formula then copy/pastespecial values

Sub X()
srcpath = "C:\SFADB"
srcbook = "random.xls"
srcsheet = "R1"
srcrng = "A2:G4001"

With ActiveSheet
.Range(srcrange).FormulaArray = "='" & srcpath & "\[" & srcbook &
"]" & srcsheet & "'!" & srcrng
.Copy
.PasteSpecial xlPasteValues
End With
Application.CutCopyMode = False

End Sub

- vdJ



"John Skewes" wrote in message
...
Hi jermsalerms,

The ranges you've given for the copy and paste (A2:A4001, B2:B4001,
C2:C4001, D2:D4001, E2:E4001, F2:F4001, G2:G4001) corresponds with the
single
range A2:G4001. In which case a single copy-paste is all that's
required...

Sub ImportData()
Application.ScreenUpdating = False
On Error Resume Next '< error = Mailer List.xls is already open
Workbooks.Open ("C:\Windows\Desktop\Mailer List.xls")
Sheets("mor01001").Range("A2:G4001").Copy _
Destination:=ThisWorkbook.Sheets("Helper
Sheet").Range("A2")
Workbooks("Mailer List.xls").Close False
Application.ScreenUpdating = True
End Sub

HTH,
John
--
The major part of getting the right answer lies in asking the right
question...


"jermsalerms" wrote:


I have data in "Mailer List.xls"
On the sheet labeled "mor01001" of this workbook I need to bring in the
data cells
A2:A4001, B2:B4001, C2:C4001, D2:D4001, E2:E4001 F2:F4001 G2:G4001


I need a macro that I can run once a month to import this data into
"Direct Mailer Template.xls"
It would need to be imported to the sheet labeled "Helper Sheet" in the
corresponding cells
A2:A4001, B2:B4001, C2:C4001, D2:D4001, E2:E4001 F2:F4001 G2:G4001


--
jermsalerms
------------------------------------------------------------------------
jermsalerms's Profile:
http://www.excelforum.com/member.php...o&userid=30167
View this thread:
http://www.excelforum.com/showthread...hreadid=498548






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to import from one closed workbook


I edited the formula to fit but it is giving me a "Compile Error: Syntax
Error"

Here is the formula...am I missing something?

Sub X()
srcpath = "C:\Documents and Settings\user\My
Documents\Spreadsheets\Data"
srcbook = "Mailer List.xls"
srcsheet = "mor01001"
srcrng = "A2:G4001"

With ActiveSheet
..Range(srcrange).FormulaArray = "='" & srcpath & "\[" & srcbook &
"]" & srcsheet & "'!" & srcrng
..Copy
..PasteSpecial xlPasteValues
End With
Application.CutCopyMode = False

End Sub


--
jermsalerms
------------------------------------------------------------------------
jermsalerms's Profile: http://www.excelforum.com/member.php...o&userid=30167
View this thread: http://www.excelforum.com/showthread...hreadid=498548

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Macro to import from one closed workbook

minor syntax error(s). edit to suit.

Sub X()
srcpath = "C:\SFADB"
srcbook = "ran dom.xls"
srcsheet = "R1"
srcrng = "d4:e5"

With Sheet1.Range(srcrng) 'correct variable and add to with statement so
it applies to copy and pastespec methods as well
.FormulaArray = "='" & srcpath & "\[" & srcbook & "]" & srcsheet &
"'!" & srcrng
.Copy
.PasteSpecial xlPasteValues
End With
Application.CutCopyMode = False

End Sub

cheers - voodooJoe


"jermsalerms"
wrote in message
...

I edited the formula to fit but it is giving me a "Compile Error: Syntax
Error"

Here is the formula...am I missing something?

Sub X()
srcpath = "C:\Documents and Settings\user\My
Documents\Spreadsheets\Data"
srcbook = "Mailer List.xls"
srcsheet = "mor01001"
srcrng = "A2:G4001"

With ActiveSheet
.Range(srcrange).FormulaArray = "='" & srcpath & "\[" & srcbook &
"]" & srcsheet & "'!" & srcrng
.Copy
.PasteSpecial xlPasteValues
End With
Application.CutCopyMode = False

End Sub


--
jermsalerms
------------------------------------------------------------------------
jermsalerms's Profile:
http://www.excelforum.com/member.php...o&userid=30167
View this thread: http://www.excelforum.com/showthread...hreadid=498548



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to import from one closed workbook


This is what I have entered into Visual Basic...when I run the macro
get error 400


Sub X()
srcpath = "C:\Documents and Settings\user\M
Documents\Spreadsheets\Data"
srcbook = "InfoUSA List.xls"
srcsheet = "mor01001"
srcrng = "a2:g4001"

With Sheet1.Range(srcrng) 'correct variable and add to with statemen
so it applies to copy and pastespec methods as well
.FormulaArray = "='" & srcpath & "\[" & srcbook & "]" & srcsheet & "'!
& srcrng
.Copy
.PasteSpecial xlPasteValues
End With
Application.CutCopyMode = False

End Su

--
jermsalerm
-----------------------------------------------------------------------
jermsalerms's Profile: http://www.excelforum.com/member.php...fo&userid=3016
View this thread: http://www.excelforum.com/showthread.php?threadid=49854

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to import from one closed workbook


I figured out the error 400 has to do with protected sheets...

now my problem is that everything is supposed to be importing to sheet
two and it goes to sheet one.

The code is written on sheet two...is there something I am doing
wrong...or is there extra coding that needs to be in there to make it
work correctly.

I must have it go to sheet two because sheet one gets imported into a
contact manager that reads the first sheet only.


--
jermsalerms
------------------------------------------------------------------------
jermsalerms's Profile: http://www.excelforum.com/member.php...o&userid=30167
View this thread: http://www.excelforum.com/showthread...hreadid=498548

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
closed workbook macro puiuluipui Excel Discussion (Misc queries) 1 July 4th 08 10:13 PM
Import data from a closed workbook David T Excel Discussion (Misc queries) 2 September 17th 07 07:24 PM
import all sheets from a closed workbook johnpetrusa Excel Programming 2 June 4th 05 11:24 PM
Import Sheet from Closed Workbook Joe Derr[_2_] Excel Programming 1 May 2nd 05 09:07 AM
Using Querytable.add to import data from a closed workbook Markus Stolle[_5_] Excel Programming 8 August 3rd 04 08:51 PM


All times are GMT +1. The time now is 01:10 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"