Solved

Removing an absolute value.  Folder path.

Posted on 2014-11-05
7
71 Views
Last Modified: 2014-11-07
I the following code I am checking to see if a specific file is open, if it is? Close it, if not? carry on.
Ln7 concerns me because it is an absolute folder location.  Is there a way to write that part out?
I have another procedure that uses that file and it needs to be closed in order to process correctly.
Please advise and thanks.

PS:  Will consider other re-writes too.  It shows my lack of VBA writing skills.


Sub IsSalesOrderDownloadTemplateOpen()
 
 Dim I As Integer
 Dim bIsOpened
    For I = 1 To Application.Workbooks.Count
        If (Application.Workbooks(I).Name = "SALESORDERDOWNLOAD.XML" _
            And Application.Workbooks(I).Path = "C:\_SAP\Extracts\SalesOrd") Then
            bIsOpened = True
            Exit For
        End If
    Next I

 
'  For i = 1 To Application.Workbooks.Count
'   bIsOpened = bIsOpened Or (Application.Workbooks(i).Name = "SALESORDERDOWNLOAD.XML" _
'   And Application.Workbooks(i).Path = "C:\_SAP\Extracts\SalesOrd")
'  Next i

  If bIsOpened Then
    MsgBox "Target save file is open, Closing file so process can use it.", vbOKOnly + vbInformation, "Cannot have: C:\_SAP\EXTRACTS\SALESORD\SALESORDERDOWNLOAD.xml open and run this process.  Close it and try again."
    Application.DisplayAlerts = False
    Windows("SALESORDERDOWNLOAD.XML").Activate
    ActiveWorkbook.Close
    bIsOpened = False
    Application.DisplayAlerts = True
    GoTo 100  'Removed Exit Sub
  Else
   GoTo 100
  End If
100  'Continue knowing that file is not open.
End Sub

Open in new window

0
Comment
Question by:RWayneH
  • 4
  • 2
7 Comments
 

Author Comment

by:RWayneH
ID: 40424100
I may have to leave that in.  I am assuming that I can use a network path like:
\\na\Global-Groups\etc.\etc.\   or even better a sharepoint site?:  
http://departments.haworthinc.com/PLM/data/Lists/IPL%20Data/DispForm.aspx?ID=38&Source=http%3A%2F%2Fdepartments%2Ehaworthinc%2Ecom%2FPLM%2Fdata%2FLists%2FIPL%2520Data%2FIPL%2520data%2Easpx

I do not know how to point to a specific sharepoint file... and how to add the code if a user does not even have access to the particular site.   I am good with leaving it in, and need to change that Ln7 to point to sharepoint location.
0
 
LVL 32

Assisted Solution

by:Rob Henson
Rob Henson earned 50 total points
ID: 40425910
If a Workbook is open then you may be able to use the Windows.Activate(FileName) command to show it.

I believe this would only need the filename.

Therefore, if the file is not open the above command would generate an error. An error handler would then skip the step or carry on with the close.

Thanks
Rob H
0
 

Author Comment

by:RWayneH
ID: 40425984
So what you are saying is it would be something like:?

If  Windows("SALESORDERDOWNLOAD.XML").Activate = False
    continue
End if

If  Windows("SALESORDERDOWNLOAD.XML").Activate = True
   Close it without saving changes.
   Continue
End if
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 450 total points
ID: 40426015
my versions of RobH idea...

dim OrderFileName as string, isOpen as boolean
OrderSheetName = "SALESORDERDOWNLOAD.XML"

on error resume next  '<<turn on error trap
isOpen = false
Windows(OrderSheetName ).Activate
if Err.Number = 0 then
   isOpen=True
 else
  isOpen = False
end if
on error goto 0  '<<turn off error trap

Open in new window

0
 

Author Comment

by:RWayneH
ID: 40426167
How would we add a if true, close file without saving changes...  I do not want alerts to stop and ask user if it is ok ....  Looks like this will work much better than the original one I had.  Thanks!!
0
 
LVL 32

Assisted Solution

by:Robberbaron (robr)
Robberbaron (robr) earned 450 total points
ID: 40428146
if IsOpen then
   ActiveWorkbook.Close SaveChanges:=False
end if

Open in new window

0
 

Author Closing Comment

by:RWayneH
ID: 40429381
Thanks for the help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now