PDA

View Full Version : [SOLVED:] PROCESSING External Excel Files



Vanzuck
03-16-2019, 05:02 AM
I have an Excel File that through VBA code opens 2 Excel files , let's name them FileA and FileB.
The OPEN statement goes well, with VISIBLE property , I can see both files.
I'm successful to et the LASTROW value for both files.
But when I try to read a cell of FileA, I don't get value!
I close everything, I try to open FileA and get the message "File n use, read only"
I'm crazy

Paul_Hossler
03-16-2019, 07:14 AM
Without seeing your macro, it's a little hard to just guess, but I'd say you're doing something wrong

Use the [#] icon and paste your macro between the tags

At least the part that does the Open and Read

Vanzuck
03-16-2019, 08:01 AM
Dim ExcelApp As Application
Dim FileCosti As Workbook
Dim ShCosti As Worksheet
Dim FileMapping As Workbook
Dim ShMapping1 As Worksheet
Dim ShMapping2 As Worksheet


Dim FileCostiName As String


Dim TOTROW, TOTAQ, TOTCC As Long
Dim R, S As Integer


Dim L1, L2, L3, L4 As String
Dim VDC, NOME As String


Rem INIZIALIZZAZIONE
Rem ================


Set ExcelApp = CreateObject("excel.application")


FileCostiName = "C:\COSTI AMS VITA\AAA.xlsx"
Set FileCosti = ExcelApp.Workbooks.Open(FileCostiName)
ExcelApp.Visible = False
Set ShCosti = FileCosti.Worksheets("Feb19")


Set FileMapping = ExcelApp.Workbooks.Open("C:\COSTI AMS VITA\MappingCosti.xlsx")
Set ShMapping1 = FileMapping.Worksheets("AQSRC003")
Set ShMapping2 = FileMapping.Worksheets("CC Costs")


TOTROW = ShCosti.Cells.SpecialCells(xlCellTypeLastCell).Row
TOTAQ = ShMapping1.Cells.SpecialCells(xlCellTypeLastCell).Row
TOTCC = ShMapping2.Cells.SpecialCells(xlCellTypeLastCell).Row


For R = 2 To TOTROW




VDC = ShCosti.Cells(R, 3).Value




Thanks Paul anyway.
The last statement VDC = ShCosti.Cells(R, 3).Value assigns "Empty" value to VDC variable. I'm sure the cell contains a not empty string.
The strange thing is that with the same code used in another file, it works.
It seems that the cells of the sheet ShCosti are "protected from reading"

Vanzuck
03-16-2019, 11:31 AM
Dim ExcelApp As Application
Dim FileCosti As Workbook
Dim ShCosti As Worksheet
Dim FileMapping As Workbook
Dim ShMapping1 As Worksheet
Dim ShMapping2 As Worksheet


Dim FileCostiName As String


Dim TOTROW, TOTAQ, TOTCC As Long
Dim R, S As Integer


Dim L1, L2, L3, L4 As String
Dim VDC, NOME As String


Rem INIZIALIZZAZIONE
Rem ================


Set ExcelApp = CreateObject("excel.application")


FileCostiName = "C:\COSTI AMS VITA\AAA.xlsx"
Set FileCosti = ExcelApp.Workbooks.Open(FileCostiName)
ExcelApp.Visible = False
Set ShCosti = FileCosti.Worksheets("Feb19")


Set FileMapping = ExcelApp.Workbooks.Open("C:\COSTI AMS VITA\MappingCosti.xlsx")
Set ShMapping1 = FileMapping.Worksheets("AQSRC003")
Set ShMapping2 = FileMapping.Worksheets("CC Costs")


TOTROW = ShCosti.Cells.SpecialCells(xlCellTypeLastCell).Row
TOTAQ = ShMapping1.Cells.SpecialCells(xlCellTypeLastCell).Row
TOTCC = ShMapping2.Cells.SpecialCells(xlCellTypeLastCell).Row


For R = 2 To TOTROW




VDC = ShCosti.Cells(R, 3).Value




Thanks Paul anyway.
The last statement VDC = ShCosti.Cells(R, 3).Value assigns "Empty" value to VDC variable. I'm sure the cell contains a not empty string.
The strange thing is that with the same code used in another file, it works.
It seems that the cells of the sheet ShCosti are "protected from reading"

Vanzuck
03-16-2019, 11:32 AM
Stop investigations, I found the issue, it was a false issue. Unfortunately the test was about a wrong cell. Apologize

Paul_Hossler
03-16-2019, 11:49 AM
No problem

You can mark it SOLVED using Thread Tools above the first post