Copy range from Temp WorkBook to Main WorkBook

Barquois

New Member
Joined
Jun 17, 2011
Messages
23
Hi guys,

I'm fairly new to VBA so excuse any n00b mistakes.

I'm having trouble with a particular script at the moment and can't seem to get it to work. I'm not even getting a meaningful message or the chance to debug. Through a process of commenting out on the script I have located the line where it's failing.

In a nutshell the script I've written opens a log file from a stated location as a temp workbook. I want to select column A to the last value in column A, copy it and past in a desired range on the main workbook.

I can't seem to get it to copy and paste. I just get a '400' error message.

Here's the code :

Sub ImportTextFile()
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
Dim SheetName As String
Dim TMPWorkBook As Workbook
Dim FilePath As String
Dim TxtFilePath As String
Dim TxtFileName As String
Dim myLastRow As Long
Dim myLastColumn As Long
<o:p> </o:p>
Application.ScreenUpdating = False
<o:p> </o:p>
Set WB = ThisWorkbook
SheetName = "Sheet1"
TxtFileName = "\\ServerName\Directory\Directory\Directory\FileName.log"
Workbooks.OpenText Filename:="\\ServerName\Directory\Directory\Directory\FileName.log"
<o:p> </o:p>
Set TMPWorkBook = ActiveWorkbook
TMPWorkBook.Sheets("SheetName").Select

*** Failing Here ****

'Range(Selection, Selection.End(xlDown)).Select
'Cells.Select
'Selection.Copy
'TMPWorkBook.Close savechanges:=False
<o:p> </o:p>
Set WB = ActiveWorkbook
'ThisWorkbook.Sheets("Sheet1").Select
'Range("E1").Select
'ActiveSheet.Paste
'Application.CutCopyMode = False
'Cells.Select
'Cells.EntireColumn.AutoFit
'ActiveSheet.Range("E1").Select
<o:p> </o:p>
Application.ScreenUpdating = True
<o:p> </o:p>
End Sub

What am I doing wrong? Any help greatly received.

Cheers

Nick


 
obviously if you only have a date one side then you're going to have to make up the time
=TIMEVALUE("00:00:00") = 12am
so it A1 = 01/07/2011 then =A1+TIMEVALUE("00:00:00") is 12am on 1st July

This is how you'd convert dates to date/time


(btw date/time dates are whole numbers 40555 and times are decimals 0.5643)

<TABLE style="WIDTH: 158pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=210><COLGROUP><COL style="WIDTH: 158pt; mso-width-source: userset; mso-width-alt: 7680" width=210><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 158pt; HEIGHT: 12.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl65 height=17 width=210 align=right>40555.5643</TD></TR></TBODY></TABLE>

<TABLE style="WIDTH: 158pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=210><COLGROUP><COL style="WIDTH: 158pt; mso-width-source: userset; mso-width-alt: 7680" width=210><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 158pt; HEIGHT: 12.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl65 height=17 width=210 align=right>12 January 2011 01:32:36 PM</TD></TR></TBODY></TABLE>

40555=
<TABLE style="WIDTH: 88pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=117><COLGROUP><COL style="WIDTH: 88pt; mso-width-source: userset; mso-width-alt: 4278" width=117><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 88pt; HEIGHT: 12.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl65 height=17 width=117 align=right>12 January 2011</TD></TR></TBODY></TABLE>

<TABLE style="WIDTH: 62pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=83><COLGROUP><COL style="WIDTH: 62pt; mso-width-source: userset; mso-width-alt: 3035" width=83><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 62pt; HEIGHT: 12.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl63 height=17 width=83 align=right>0.5643=
1:32:36PM
</TD></TR></TBODY></TABLE> of any day
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,225,149
Messages
6,183,179
Members
453,151
Latest member
Lizamaison

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top