Consulting

Results 1 to 6 of 6

Thread: PROCESSING External Excel Files

  1. #1
    VBAX Regular
    Joined
    Mar 2019
    Posts
    6
    Location

    PROCESSING External Excel Files

    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

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    Mar 2019
    Posts
    6
    Location
    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"

  4. #4
    VBAX Regular
    Joined
    Mar 2019
    Posts
    6
    Location
    Quote Originally Posted by Vanzuck View Post
    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"

  5. #5
    VBAX Regular
    Joined
    Mar 2019
    Posts
    6
    Location
    Stop investigations, I found the issue, it was a false issue. Unfortunately the test was about a wrong cell. Apologize

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    No problem

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

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •