致所有中小企业, 这是我在这里的第一个港口。我正在研究过去几天的vba代码。我的编码不是很好,因此我需要一些专家的帮助来解决这个问题。
我总共有3个excels:,(1)List_Of_Files。 (2)PARAMETER_FILE和(3)源文件。
我在过去几天正在研究这个问题,并构建了以下代码。但我无法做到以下事情:
以下是我的代码。请帮我解决这个问题。我在谷歌和这个网站上搜索过,但无法获得任何解决方案。
Sub Test_File_Exist_FSO_Late_binding()
Dim FSO As Object
Dim FilePath As String
Set FSO = CreateObject("scripting.filesystemobject")
FilePath = " "
If FSO.FileExists(FilePath) = False Then
MsgBox "file doesn't exist"
Else
Call COPYCELL
End If
End Sub
Sub COPYCELL()
Dim wbk As Workbook
Dim x%
Application.DisplayAlerts = False
strParamFile = "C:\Users\rezaul.hasan\Desktop\Practice\PARAMETER_FILE.xlsx" 'this is the mapping excel
Workbooks.Open Filename:="C:\Users\rezaul.hasan\Desktop\Practice\PARAMETER_FILE.xlsx"
Sheets("DIGITAL").Select
TargetFilename = Range("G2").Value
SourceFilename = Range("A2").Value
SourceTabName = Range("B2").Value
Set wbkt = Workbooks.Add
wbkt.SaveAs Filename:="C:\Users\rezaul.hasan\Desktop\Practice\" & TargetFilename & ".xlsx", FileFormat:=51
wbkt.Close
strFirstFile = "C:\Users\rezaul.hasan\Desktop\Practice\" & SourceFilename & ".xlsx" 'Take the source excel
strSecondFile = "C:\Users\rezaul.hasan\Desktop\Practice\" & TargetFilename & ".xlsx" 'take the target excel
Set wbkM = Workbooks.Open(strParamFile)
Set sh1 = Sheets("DIGITAL")
lr = Range("C" & Rows.Count).End(xlUp).Row
For x = 2 To 4
Source = sh1.Range("C" & x).Value
Target1 = sh1.Range("E" & x).Value
Target2 = sh1.Range("F" & x).Value
Set wbkS = Workbooks.Open(strFirstFile)
With wbkS.Sheets(SourceTabName)
.Range(Source).Copy
End With
Set wbk = Workbooks.Open(strSecondFile)
With wbk.Sheets("Sheet1")
.Range(Target1, Target2).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End With
wbk.Save
wbk.Close
wbkS.Close
Next
wbkM.Close
End Sub