For the operation of the VBA in the workbook there is no problem, excuse me how to operate the data in another workbook? I have a case, please expert help me have a look, modification is mainly below to read and write another part of the workbook, I according to the following code to run after another workbook open normally, but not to read and write operations.
Private Sub CommandButton1_Click ()
Dim n1 As Single
Dim m1 As Single
VBA in the workbook n1=14 'control lines, assignment of rows of 14,15,16
M1=14 'control another workbook rows, assignment of rows of 14,15,16
'realization function: every two seconds for VBA in the workbook and at the same time a row data in another workbook assignment (for instance assignment into, and a row of the world, the next two seconds is the place for the next line), a total of assignment 3 times -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
'the activity of VBA in the workbook work table name is Sheet21, another workbook activity work table name is Sheet25 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
For I=1 To 3
Application. Wait (Now + TimeValue (" 00:00:02 ")) 'setting time interval
'for VBA in the workbook Sheet21 assignment -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
For j=2 To 10 'For the first column 2 To 10 n1 line assignment
Sheet21. Cells (n1, j) Value=https://bbs.csdn.net/topics/Sheet21.Cells (n1-1, j). The Value
Next j
N1 n1 + 1=
'for another workbook Sheet25 do the same in the assignment (the following is the place where a problem) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Dim wb As Excel. The Workbook
Set wb=Workbooks. Open (" C: \ Users \ \ Administrator \ Desktop \ statements. XLS ")
Wb. Activate
For q=2 To 37
Wb. Sheets (25) Cells (m1, q) Value=https://bbs.csdn.net/topics/wb.Sheets (25) Cells (m1-1, q). The Value
The Next q
M1=m1 + 1
Wb. Save
Wb. Close
Next I
End Sub
CodePudding user response:
Set wb=Workbooks. Open (" C: \ Users \ \ Administrator \ Desktop \ statements. XLS ")
The Debug. Print wb. Sheets (25). The Name '& lt; -
Wb. Activate
Manual open "statements. XLS" :
Confirm the above output work is expected to be modified pages;
Confirm line 13 data;
Manually fill in the 14 ~ 16 rows, save not wrong;
Shut down for 2 seconds to open again, such as confirmation data didn't lose,
CodePudding user response:
Your "operating another workbook" code, looks no problem ah,The operation of "purpose" is to: statements. XLS in Sheets (25) 2 line 13 to 37, cell content,
Copy to the following 14 to 16 in the corresponding cell line,
Your code is running, it is there any error message?
You said in your ZhuTie to read and write operations "" no, you confirm line 13 is not" empty line "?
In addition:
Control variables "line number" n1, m1, why not Long or Integer types, and use Single?
Several other variable I, j, q, "define" why not?
CodePudding user response:
Caution is ship ten thousand,Need to write auxiliary debug log to a file,
CodePudding user response:
Continue to see tonight, look for resources