Results 1 to 4 of 4

Error 1004 *cannot spot any problem*

Threaded View

  1. #1
    Registered User
    Join Date
    05-20-2015
    Location
    HK
    MS-Off Ver
    2010
    Posts
    9

    Error 1004 *cannot spot any problem*

    Hi everyone, I am not very familiar with VBA and I used the code below to import data from one workbook to another.
    The data does import to the selected cells but if I click cancel after the file directory comes out, I get the 1004 error and its saying the underlined line is wrong. Also, the file opened for data import asks if I would like to save the changes after it is opened. Is there a way to make it go away too? Please let me know how I can fix this. Thank you very much!
    Sub 按鈕1_Click()
    ' Get customer workbook...
    Dim customerBook As Workbook
    Dim filter As String
    Dim caption As String
    Dim customerFilename As String
    Dim customerWorkbook As Workbook
    Dim targetWorkbook As Workbook
    
    ' make weak assumption that active workbook is the target
    Set targetWorkbook = Application.ActiveWorkbook
    
    ' get the customer workbook
    filter = "Text files (*.xlsx),*.xlsx"
    caption = "Please Select an input file "
    customerFilename = Application.GetOpenFilename(filter, , caption)
    
    
    Set customerWorkbook = Application.Workbooks.Open(customerFilename)
    
    ' assume range is A1 - C10 in sheet1
    ' copy data from customer to target workbook
    Dim targetSheet As Worksheet
    Set targetSheet = targetWorkbook.Worksheets(1)
    Dim sourceSheet As Worksheet
    Set sourceSheet = customerWorkbook.Worksheets(1)
    
    targetSheet.Range("J4", "J43").Value = sourceSheet.Range("I16", "I50").Value
    
    
    ' Close customer workbook
    customerWorkbook.Close
    
    
    End Sub
    Last edited by alicelia; 05-20-2015 at 05:04 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA Vlookup Problem - run time error '1004'
    By rsami in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-11-2013, 11:13 AM
  2. 1004 Runtime error problem
    By jp001 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-20-2009, 03:23 AM
  3. Another 1004 error problem
    By Glio in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-28-2008, 10:30 AM
  4. Problem Run-time error '1004'
    By PeterSi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-18-2007, 08:46 AM
  5. Problem with macro: 1004 error
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-01-2005, 02:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1