2

我已经尝试在存储库中搜索上述问题的解决方案,但我的 VBA 基础很简陋,我无法找到答案。任何指导将不胜感激。

运行下面的代码时,会在以下行出错:

PartNumber = Range("E" & myrow).Value

代码是运行时错误“1004”:方法“对象范围”_Global 失败。

Dim objDrv      As Object
Dim strMsg      As String


For Each objDrv In CreateObject("Scripting.FileSystemObject").drives
    Select Case objDrv.DriveType
        Case 0: strMsg = strMsg & vbNewLine & objDrv.driveletter & ": Unknown"
        Case 1: strMsg = strMsg & vbNewLine & objDrv.driveletter & ": Removable Drive"
        Case 2: strMsg = strMsg & vbNewLine & objDrv.driveletter & ": Hard Disk Drive"
        Case 3: strMsg = strMsg & vbNewLine & objDrv.driveletter & ": Network Drive"
        'Case 4: strMsg = strMsg & vbNewLine & objDrv.driveletter & ": CDROM Drive"
        Case 5: strMsg = strMsg & vbNewLine & objDrv.driveletter & ": RAM Disk Drive"
    End Select
Next

Set objDrv = Nothing
'MsgBox strMsg, vbInformation

Dim sdcard As String

sdcard = InputBox( _
"Confirm which drive you wnat to create the romdata directory in." & vbNewLine & vbNewLine & "Drives Found:" _
& strMsg & vbNewLine, _
"Choose SD Card Letter.", _
"Type your file name here")
If Len(sdcard) = 1 Then
MsgBox "You have selcted the " & sdcard & " drive."
        ElseIf Len(sdcard) >= 2 Then
    MsgBox " Too many characters"
    ElseIf Len(sdcard) <= 0 Then
End If

Dim myLoop As Integer

For myLoop = 7 To 9000

    If Len(Range("I" & myLoop).Value) > 0 Then

Dim aTemp As String
Dim bTemp As String
Dim dTemp As String
Dim eTemp As String
Dim subdir As String
Dim PartNumber As String
Dim otemp As String
Dim ptemp As String

aTemp = sdcard & Chr(58) & "\romdata\"
a1temp = sdcard & Chr(58) & "\romdata"
bTemp = strMsg
PartNumber = Range("E" & myrow).Value
otemp = PartNumber & ".fwu"
ptemp = "\" & PartNumber
dTemp = ActiveWorkbook.pATH
eTemp = "\Firmware files"
subdir = "\Firmware Files\" & PartNumber & "\" & otemp

MsgBox "The full path to this file is " & dTemp & "\" & PartNumber

If dir(dTemp & subdir) = "" Then
MsgBox "The file you have selected, (" & PartNumber & ") will not be copied." & vbNewLine & _
"Please check the file is suitable for uploading to the device using an SD card." & vbNewLine & _
"(It should have a .fwu extension.)"
Exit Sub
End If

MsgBox "The file " & otemp & " is being copied to " & aTemp

 If Len(dir(aTemp, vbDirectory)) = 0 Then
MkDir a1temp

End If


FileCopy dTemp & subdir, aTemp & otemp
4

1 回答 1

3

myrow从未在您发布的片段中定义。在使用它之前定义它。

于 2013-04-22T22:10:15.547 回答