Solved

open excel file from code

Posted on 2016-08-17
6
84 Views
Last Modified: 2016-08-17
excel 2010 vba

I have a command button on a form to open excel files.
I need it revamped to: Only open a specific excel file name(provided in code) from a specific folder on a server

MyFile.xls
or
MyFile.xlsx



10.xx.xxx.xx\c:\mydata\folderTemp


Sub XET_OpenAllXfilesInFolder()
    fldr = GetFolder(ActiveWorkbook.Path)
    xfile = Dir(fldr & "\*.xlsx")
    Do While xfile <> ""
        Workbooks.Open Filename:=fldr & "\" & xfile
    Loop
End Sub
0
Comment
Question by:fordraiders
  • 4
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
Martin Andrews earned 500 total points
ID: 41760001
You simply need to use the open function with the hardcoded values for fpath and fname

Dim owb As Workbook
owb = Workbooks.Open(fpath & "\" & fname)

Open in new window

0
 
LVL 3

Author Comment

by:fordraiders
ID: 41760018
getting object variable with block varaiable not set.
0
 
LVL 3

Author Comment

by:fordraiders
ID: 41760035
Dim sPath As String
Dim sFile As String
Dim sDir As String
Dim oLB As Workbook
Dim i1 As Long
Dim iMax As Long
 
sPath = "C:\Program Files\prise\iuom\"
sDir = FileSystem.Dir(sPath & "Version_iUom_Enterprise.xls", vbNormal)
 
    Set oLB = Workbooks.Open(sPath & sDir)


This working with no errors but i do not see the workbook.
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 3

Author Comment

by:fordraiders
ID: 41760044
Workbooks.Application.Visible = true
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 41760045
Thanks
0
 
LVL 2

Expert Comment

by:Martin Andrews
ID: 41760050
If your original code was working ng, you can simply use that, the point is that you simply set it manually in your code rather than letting the user select it:

Dim own as Workbook
Workbooks.Open Filename:=fpath & "\" & fname
Set owb = ActiveWorkbook

Open in new window

0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question