Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default copying from one file pasting in another


I have this code That is suppose to open a file copy all its contents
and then paste it in the current file.but there is an error (see
below)


Sub CombineFiles2()

ActiveCell.SpecialCells(xlLastCell).Select
ActiveWindow.LargeScroll Down:=1
ActiveCell.Select
ActiveWindow.LargeScroll Down:=1
ActiveCell.Select
Selection.End(xlToLeft).Select

MyBook = ActiveWorkbook.Name
MyTargetCell = ActiveCell.Address
MySource = PickFolder("C:\")

t = Dir(MySource + "\*PageKey*.*")
Workbooks.Open Filename:=t '<-------------------------- error: can't
find file (even though I know its there)
Range("A1").Select
Set myRange = Range(Selection,
ActiveCell.SpecialCells(xlCellTypeLastCell))

myRange.Copy
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
Workbooks(MyBook).Activate
Range(MyTargetCell).Select
ActiveSheet.Paste

End Sub

Function PickFolder(strStartDir As Variant) As String
Application.DisplayAlerts = False
Dim SA As Object, f As Object
Set SA = CreateObject("Shell.Application")
Set f = SA.BrowseForFolder(0, "Choose a folder", 0, strStartDir)
If (Not f Is Nothing) Then
PickFolder = f.Items.Item.Path
End If
Set f = Nothing
Set SA = Nothing
End Function


--
tim64
------------------------------------------------------------------------
tim64's Profile: http://www.excelforum.com/member.php...o&userid=23295
View this thread: http://www.excelforum.com/showthread...hreadid=385438

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default copying from one file pasting in another

Add this line temporarily before your error line and you should see your
problem:

Msgbox t

Your variable problably does not contain the correct path/filename.

--
Damon Longworth

Don't miss out on the 2005 Excel User Conference
Sept 16th and 17th
Stockyards Hotel - Ft. Worth, Texas
www.ExcelUserConference.com


"tim64" wrote in
message ...

I have this code That is suppose to open a file copy all its contents
and then paste it in the current file.but there is an error (see
below)


Sub CombineFiles2()

ActiveCell.SpecialCells(xlLastCell).Select
ActiveWindow.LargeScroll Down:=1
ActiveCell.Select
ActiveWindow.LargeScroll Down:=1
ActiveCell.Select
Selection.End(xlToLeft).Select

MyBook = ActiveWorkbook.Name
MyTargetCell = ActiveCell.Address
MySource = PickFolder("C:\")

t = Dir(MySource + "\*PageKey*.*")
Workbooks.Open Filename:=t '<-------------------------- error: can't
find file (even though I know its there)
Range("A1").Select
Set myRange = Range(Selection,
ActiveCell.SpecialCells(xlCellTypeLastCell))

myRange.Copy
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
Workbooks(MyBook).Activate
Range(MyTargetCell).Select
ActiveSheet.Paste

End Sub

Function PickFolder(strStartDir As Variant) As String
Application.DisplayAlerts = False
Dim SA As Object, f As Object
Set SA = CreateObject("Shell.Application")
Set f = SA.BrowseForFolder(0, "Choose a folder", 0, strStartDir)
If (Not f Is Nothing) Then
PickFolder = f.Items.Item.Path
End If
Set f = Nothing
Set SA = Nothing
End Function


--
tim64
------------------------------------------------------------------------
tim64's Profile:
http://www.excelforum.com/member.php...o&userid=23295
View this thread: http://www.excelforum.com/showthread...hreadid=385438



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default copying from one file pasting in another


no its the right pat

--
tim6
-----------------------------------------------------------------------
tim64's Profile: http://www.excelforum.com/member.php...fo&userid=2329
View this thread: http://www.excelforum.com/showthread.php?threadid=38543

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default copying from one file pasting in another

How about changing:

Workbooks.Open Filename:=t
to
Workbooks.Open Filename:=mysource & t

(ps. & is usually used to concatenate strings. A plus is usually used to add
numbers. (VBA is very forgiving, but can sometimes guess incorrectly.)

Dir(MySource & "\*PageKey*.*")
(I changed the + to &.)
Will return just the filename--no drive, no path.


tim64 wrote:

I have this code That is suppose to open a file copy all its contents
and then paste it in the current file.but there is an error (see
below)

Sub CombineFiles2()

ActiveCell.SpecialCells(xlLastCell).Select
ActiveWindow.LargeScroll Down:=1
ActiveCell.Select
ActiveWindow.LargeScroll Down:=1
ActiveCell.Select
Selection.End(xlToLeft).Select

MyBook = ActiveWorkbook.Name
MyTargetCell = ActiveCell.Address
MySource = PickFolder("C:\")

t = Dir(MySource + "\*PageKey*.*")
Workbooks.Open Filename:=t '<-------------------------- error: can't
find file (even though I know its there)
Range("A1").Select
Set myRange = Range(Selection,
ActiveCell.SpecialCells(xlCellTypeLastCell))

myRange.Copy
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
Workbooks(MyBook).Activate
Range(MyTargetCell).Select
ActiveSheet.Paste

End Sub

Function PickFolder(strStartDir As Variant) As String
Application.DisplayAlerts = False
Dim SA As Object, f As Object
Set SA = CreateObject("Shell.Application")
Set f = SA.BrowseForFolder(0, "Choose a folder", 0, strStartDir)
If (Not f Is Nothing) Then
PickFolder = f.Items.Item.Path
End If
Set f = Nothing
Set SA = Nothing
End Function

--
tim64
------------------------------------------------------------------------
tim64's Profile: http://www.excelforum.com/member.php...o&userid=23295
View this thread: http://www.excelforum.com/showthread...hreadid=385438


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default copying from one file pasting in another


:) thank you that was it :

--
tim6
-----------------------------------------------------------------------
tim64's Profile: http://www.excelforum.com/member.php...fo&userid=2329
View this thread: http://www.excelforum.com/showthread.php?threadid=38543



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
copying pasting Coach Mike Wyatt Excel Programming 6 March 21st 05 12:27 AM
Pasting formulas without copying file ref. John Tolman[_2_] Excel Programming 1 July 15th 04 02:31 AM
Copying & Pasting Michael[_10_] Excel Programming 1 August 28th 03 11:00 AM
Copying rows from one file and pasting into a new file Tina Excel Programming 0 August 25th 03 04:34 AM
Copying rows from one file and pasting into a new file Stan Bauer Excel Programming 3 August 24th 03 10:41 PM


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