Results 1 to 16 of 16

Thread: [RESOLVED] Can't see file opened with 'Open file for Input', etc, etc

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    50

    Resolved [RESOLVED] Can't see file opened with 'Open file for Input', etc, etc

    I am using the fiollowing code to check for files in a dir and then open sequencially.

    Do Until EGFile = ""
    FileNum = FreeFile
    Open EGFile For Input Access Read Shared As FileNum

    'more code here'

    Close FileNum
    EGFile = Dir
    Loop

    My problem is that after the 'Open EGFile....' code I cannot see the file in Excel or use any code to pull data from various cell references within the worksheet. Do I need to activate the file somehow?


    Thanks in advance.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Can't see file opened with 'Open file for Input', etc, etc

    In the "more code here" do you have the "Input FileNum, strMyVar"?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    50

    Re: Can't see file opened with 'Open file for Input', etc, etc

    Just had code to pull bits of data from the 'opened' file.

    Strangely did manage to get this to work yesterday, but can't make it work anymore.

    What else do i need to activate the file?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Can't see file opened with 'Open file for Input', etc, etc

    What do you mean by cant see the file in Excel? Is it a csv or plain text?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    50

    Re: Can't see file opened with 'Open file for Input', etc, etc

    Have just tried -

    Workbooks.Open EGFile

    and this seems to have worked.

    I am somewhat confused tho. Why didn't 'Open EGfile for Input', etc work? Thought this would open the file for Read access?

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    50

    Re: Can't see file opened with 'Open file for Input', etc, etc

    File is .xls and when Alt+Tab to Excel App file isn't open.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Can't see file opened with 'Open file for Input', etc, etc

    Open EGFile for Input is Basic File I/O where as Workbooks.Open is an Excel method for opening a file IN Excel. One is behind the scenes and the other is in front of the scene, so to speak.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    50

    Re: Can't see file opened with 'Open file for Input', etc, etc

    I see, so if I want to use 'Open EGfile', can I not then pull data from the worksheets?

    Like I said, I did manage to do this yesterday, but unsure how I did it.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Can't see file opened with 'Open file for Input', etc, etc

    Yes you can but you need to either loop reading each line of the text file placing each value in the sheet or reading it in all at once into an array and porting that into your sheet.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    50

    Re: Can't see file opened with 'Open file for Input', etc, etc

    So when using .xls files and needing data from specific cells I assume it would be best to use 'Worksheets.Open' command rather than 'Open EGFile' command?

    If using this routine do I need assign a filenumber and then use 'Open EGFile' or can I do away with this code altogether?

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Can't see file opened with 'Open file for Input', etc, etc

    If your opening xls files then you need to better use the .Open method. If you needing a plain textfile, no delimiters, the Basic File I/O is what you need.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    50

    Re: Can't see file opened with 'Open file for Input', etc, etc

    Ok, think I am sorted now.

    Many thanks for your help with this.

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Can't see file opened with 'Open file for Input', etc, etc

    No problem Glad to have helped.

    Ps, sop was it just a textfile or a xls file that you wanted to open?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    50

    Re: [RESOLVED] Can't see file opened with 'Open file for Input', etc, etc

    file is a .xls

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Can't see file opened with 'Open file for Input', etc, etc

    Oh, ok. Then definately yes as you would do a ...
    VB Code:
    1. Application.Workbooks.Open "C:\MyBook.xls"
    2. MsgBox Application.Workbooks("MyBook.xls").Sheets(Sheet1").Cells(1, 1)
    Type of logic. If you need to do this from inside Excels VBA then its easier then doing it from another language like VB6 although its almost the same.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  16. #16

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    50

    Re: [RESOLVED] Can't see file opened with 'Open file for Input', etc, etc

    Much appreciated!!!

Posting Permissions

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



Click Here to Expand Forum to Full Width