Hey, I am working on a program with multiple excel files, copying the same cells off each one, and adding the transpose of all of them to a table in access. The programming is in vba in access. However, the pasteSpecial method isn’t working for me, and I’m always getting a “pastespecial method of range class failed”. I tried a lot of things already but nothing seems to work.
So I tried something simpler, simply adding values to an excel document, copying and pasting the transpose two cells over with the pasteSpecial. But it’s STILL not working. When I run the program with the excel program open to see what’s going on, I see the data’s copied, and the cell E1 is selected, but it's not pasting. I can go in and manually press pasteSpecial, transpose. But the coding isn't running this part of the program, and is consistently throwing the "pastespecial method of range class failed" error.
Can someone see what I’m doing wrong with this simple program, and hopefully I can apply it to the more complicated program?
Thanks a million.
Sub Testing ()
Set objAccess = CreateObject("Access.Application")
objAccess.OpenCurrentDatabase "C:\Database2.accdb"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add
objWorkbook.Sheets("Sheet1").Range("A2") = "A"
objWorkbook.Sheets("Sheet1").Range("A3") = "B"
objWorkbook.Sheets("Sheet1").Range("A4") = "C"
objWorkbook.Sheets("Sheet1").Range("B1") = "1"
objWorkbook.Sheets("Sheet1").Range("C1") = "2"
objWorkbook.Sheets("Sheet1").Range("D1") = "3"
objWorkbook.Sheets("Sheet1").Range("B2") = "x"
objWorkbook.Sheets("Sheet1").Range("C2") = "y"
objWorkbook.Sheets("Sheet1").Range("D2") = "z"
objWorkbook.Sheets("Sheet1").Range("B3") = "i"
objWorkbook.Sheets("Sheet1").Range("C3") = "j"
objWorkbook.Sheets("Sheet1").Range("D3") = "k"
objWorkbook.Sheets("Sheet1").Range("B4") = "5"
objWorkbook.Sheets("Sheet1").Range("C4") = "6"
objWorkbook.Sheets("Sheet1").Range("D4") = "7"
objWorkbook.Sheets("Sheet1").Range("A1:D4").Copy
objWorkbook.Sheets("Sheet1").Range("E1").PasteSpecial Paste:=xlFormats, Operation:=xlNone, _
SkipBlanks:=True, Transpose:=True
End Sub
So I tried something simpler, simply adding values to an excel document, copying and pasting the transpose two cells over with the pasteSpecial. But it’s STILL not working. When I run the program with the excel program open to see what’s going on, I see the data’s copied, and the cell E1 is selected, but it's not pasting. I can go in and manually press pasteSpecial, transpose. But the coding isn't running this part of the program, and is consistently throwing the "pastespecial method of range class failed" error.
Can someone see what I’m doing wrong with this simple program, and hopefully I can apply it to the more complicated program?
Thanks a million.
Sub Testing ()
Set objAccess = CreateObject("Access.Application")
objAccess.OpenCurrentDatabase "C:\Database2.accdb"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add
objWorkbook.Sheets("Sheet1").Range("A2") = "A"
objWorkbook.Sheets("Sheet1").Range("A3") = "B"
objWorkbook.Sheets("Sheet1").Range("A4") = "C"
objWorkbook.Sheets("Sheet1").Range("B1") = "1"
objWorkbook.Sheets("Sheet1").Range("C1") = "2"
objWorkbook.Sheets("Sheet1").Range("D1") = "3"
objWorkbook.Sheets("Sheet1").Range("B2") = "x"
objWorkbook.Sheets("Sheet1").Range("C2") = "y"
objWorkbook.Sheets("Sheet1").Range("D2") = "z"
objWorkbook.Sheets("Sheet1").Range("B3") = "i"
objWorkbook.Sheets("Sheet1").Range("C3") = "j"
objWorkbook.Sheets("Sheet1").Range("D3") = "k"
objWorkbook.Sheets("Sheet1").Range("B4") = "5"
objWorkbook.Sheets("Sheet1").Range("C4") = "6"
objWorkbook.Sheets("Sheet1").Range("D4") = "7"
objWorkbook.Sheets("Sheet1").Range("A1:D4").Copy
objWorkbook.Sheets("Sheet1").Range("E1").PasteSpecial Paste:=xlFormats, Operation:=xlNone, _
SkipBlanks:=True, Transpose:=True
End Sub