JKettelarij
Nieuwe gebruiker
- Lid geworden
- 20 dec 2012
- Berichten
- 4
Hallo,
Kan iemand mij uitleggen hoe ik in VBA een range cellen uit een gesloten werkblad kan knippen en die plakken in het bestand dat ik open heb staan.
Via onderstaande code importeer ik tekst maar nu zou ik graag een range (c7:F267) willen importeren.
Sub Import()
'
Application.ScreenUpdating = False
Dim VolledigeNaam As String
VolledigeNaam = Application.GetOpenFilename("Alle bestanden (*.CLC), *.*", Title:="Selecteer het bestand om te importeren")
Sheets("Import").Select
Rows("2:2400").Select
Selection.ClearContents
On Error GoTo einde
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & VolledigeNaam, Destination:=Range("$A$2"))
.Name = "12-086-4-8-11"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "'"
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Rows("2:2400").Select
Selection.Replace What:=" ", Replacement:="-", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Cells.Select
Cells.EntireColumn.AutoFit
Het bestandje waaruit ik dit wil doen is iedere keer een andere.
Alvast bedankt.
M.Vr.Gr J Kettelarij
Kan iemand mij uitleggen hoe ik in VBA een range cellen uit een gesloten werkblad kan knippen en die plakken in het bestand dat ik open heb staan.
Via onderstaande code importeer ik tekst maar nu zou ik graag een range (c7:F267) willen importeren.
Sub Import()
'
Application.ScreenUpdating = False
Dim VolledigeNaam As String
VolledigeNaam = Application.GetOpenFilename("Alle bestanden (*.CLC), *.*", Title:="Selecteer het bestand om te importeren")
Sheets("Import").Select
Rows("2:2400").Select
Selection.ClearContents
On Error GoTo einde
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & VolledigeNaam, Destination:=Range("$A$2"))
.Name = "12-086-4-8-11"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "'"
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Rows("2:2400").Select
Selection.Replace What:=" ", Replacement:="-", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Cells.Select
Cells.EntireColumn.AutoFit
Het bestandje waaruit ik dit wil doen is iedere keer een andere.
Alvast bedankt.
M.Vr.Gr J Kettelarij