设置将粘贴范围的输入框
Set up an input box where the range will be pasted
我在 YouTube 上观看了这个视频,它确实对我帮助很大,现在我必须改进该代码。所以在代码中,粘贴值的行在哪里我必须设置输入框或其他东西,让用户选择他想粘贴的地方。这是我的代码:
Sub IMPORT_DATA()
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Application.ScreenUpdating = False
FileToOpen = Application.GetOpenFilename(Title:="Browse for your File & Import Range", FileFilter:="Excel Files(*.xlsx),*xlsx")
If FileToOpen <> False Then
Set OpenBook = Application.Workbooks.Open(FileToOpen)
OpenBook.Sheets("NELT report").Range("R7:R14").Copy
ThisWorkbook.Worksheets("Dispatch Monthly NETO").Range("L5").PasteSpecial xlPasteValues
OpenBook.Close False
Range("L5:L12").Interior.Color = RGB(255, 242, 204)
End If
Application.ScreenUpdating = True
End Sub
Sub IMPORT_DATA()
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Dim s As String ' Range to Paste
Application.ScreenUpdating = False
FileToOpen = Application.GetOpenFilename(Title:="Browse for your File & Import
Range", FileFilter:="Excel Files(*.xlsx),*xlsx")
If FileToOpen <> False Then
Set OpenBook = Application.Workbooks.Open(FileToOpen)
OpenBook.Sheets("NELT report").Range("R7:R14").Copy
s = InputBox("Range to Paste : ")
If s = "" Then Exit Sub
ThisWorkbook.Worksheets("Dispatch Monthly NETO").Range(s).PasteSpecial
xlPasteValues
OpenBook.Close False
Range("L5:L12").Interior.Color = RGB(255, 242, 204)
End If
Application.ScreenUpdating = True
End Sub
我在 YouTube 上观看了这个视频,它确实对我帮助很大,现在我必须改进该代码。所以在代码中,粘贴值的行在哪里我必须设置输入框或其他东西,让用户选择他想粘贴的地方。这是我的代码:
Sub IMPORT_DATA()
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Application.ScreenUpdating = False
FileToOpen = Application.GetOpenFilename(Title:="Browse for your File & Import Range", FileFilter:="Excel Files(*.xlsx),*xlsx")
If FileToOpen <> False Then
Set OpenBook = Application.Workbooks.Open(FileToOpen)
OpenBook.Sheets("NELT report").Range("R7:R14").Copy
ThisWorkbook.Worksheets("Dispatch Monthly NETO").Range("L5").PasteSpecial xlPasteValues
OpenBook.Close False
Range("L5:L12").Interior.Color = RGB(255, 242, 204)
End If
Application.ScreenUpdating = True
End Sub
Sub IMPORT_DATA()
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Dim s As String ' Range to Paste
Application.ScreenUpdating = False
FileToOpen = Application.GetOpenFilename(Title:="Browse for your File & Import
Range", FileFilter:="Excel Files(*.xlsx),*xlsx")
If FileToOpen <> False Then
Set OpenBook = Application.Workbooks.Open(FileToOpen)
OpenBook.Sheets("NELT report").Range("R7:R14").Copy
s = InputBox("Range to Paste : ")
If s = "" Then Exit Sub
ThisWorkbook.Worksheets("Dispatch Monthly NETO").Range(s).PasteSpecial
xlPasteValues
OpenBook.Close False
Range("L5:L12").Interior.Color = RGB(255, 242, 204)
End If
Application.ScreenUpdating = True
End Sub