Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Why Won't This Code Work????

Why can't I get this to work? NewFN always equals the file I selected but
wbExt always equals "nothing" and the routine crashes. I can't figure out
what I'm doing wrong.
Thanks in advance,
Todd

Private Sub CommandButton1_Click()
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls),
*.xls", Title:="Select a file")
If NewFN = False Then
MsgBox "No File Was Selected"
Else
Workbooks.Open FileName:=NewFN

Dim wbExt As Workbook
Set wbExt = NewFN
wbExt.Worksheets("Sheet1").Range("C4").Copy

Application.CutCopyMode = False
wbExt.Close savechanges:=False
Set wbExt = Nothing

End If
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Why Won't This Code Work????

It crashes because NewFN is a string and wbExt is a workbook so you
can't set one equal to the other.

You could try:

Set wbExt = Workbooks(Right(NewFN, InStrRev(NewFN, "\")))

Hope this helps
Rowan

TK wrote:
Why can't I get this to work? NewFN always equals the file I selected but
wbExt always equals "nothing" and the routine crashes. I can't figure out
what I'm doing wrong.
Thanks in advance,
Todd

Private Sub CommandButton1_Click()
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls),
*.xls", Title:="Select a file")
If NewFN = False Then
MsgBox "No File Was Selected"
Else
Workbooks.Open FileName:=NewFN

Dim wbExt As Workbook
Set wbExt = NewFN
wbExt.Worksheets("Sheet1").Range("C4").Copy

Application.CutCopyMode = False
wbExt.Close savechanges:=False
Set wbExt = Nothing

End If
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Why Won't This Code Work????

just a simple change is all, you pretty much had it....

Private Sub CommandButton1_Click()
Dim wbExt As Workbook

NewFN = _
Application.GetOpenFilename("Excel Files (*.xls), _
*.xls","Select a file")
If NewFN = False Then
MsgBox "No File Was Selected"
Else
Set wbExt = Workbooks.Open(NewFN)
wbExt.Worksheets("Sheet1").Range("C4").Copy

Application.CutCopyMode = False
wbExt.Close savechanges:=False
Set wbExt = Nothing
End If
End Sub





"TK" wrote:

Why can't I get this to work? NewFN always equals the file I selected but
wbExt always equals "nothing" and the routine crashes. I can't figure out
what I'm doing wrong.
Thanks in advance,
Todd

Private Sub CommandButton1_Click()
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls),
*.xls", Title:="Select a file")
If NewFN = False Then
MsgBox "No File Was Selected"
Else
Workbooks.Open FileName:=NewFN

Dim wbExt As Workbook
Set wbExt = NewFN
wbExt.Worksheets("Sheet1").Range("C4").Copy

Application.CutCopyMode = False
wbExt.Close savechanges:=False
Set wbExt = Nothing

End If
End Sub



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
Code Does Not Work Minitman[_4_] Excel Programming 21 December 16th 04 09:30 PM
why this code doesn't work? 71paolo71[_4_] Excel Programming 7 May 6th 04 10:06 PM
Code won't work? Joe 90 Excel Programming 3 October 2nd 03 04:26 AM
Why my code do not work : - ( keepitcool Excel Programming 5 September 5th 03 06:28 PM
Why my code do not work : - ( Tom Ogilvy Excel Programming 1 August 31st 03 04:53 PM


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