M
maperalia
I have a file to archive data (see below). However, when the file that I
suppose to archive the data (color.xls) is open my program crashes. I would
like to know if the program can recognize the following:
If the color.xls file is open then close it. So the program can be run
without problem.
Thanks in advance.
Maperalia.
'********************START PROGRAM************************
'CREATE DATABASE
Dim sr As Range
Dim dr As Range
Dim dwb As Workbook
Dim Lr As Long
Dim hl As String
'Where:
'Lr = Last Row
'dr = destination Range
'dwb = destination WorkBook
'sr = source range
'***************************************************
'***************************************************
'OPEN THE FILE TO ARCHIVE INFORMATION
Application.ScreenUpdating = False
If bIsBookOpen("color.xls") Then
Set dwb = Workbooks("color.xls")
Else
'***************************************************
'REMOVE READ ONLY
SetAttr "C:\Test\Pants\color.xls", vbNormal
'***************************************************
Set dwb = Workbooks.Open("C:\Test\Pants\color.xls ")
End If
'***************************************************************
'WRITE THE DATABASE
UserForm1.Repaint
Application.ScreenUpdating = False
UserForm1.Repaint
Lr = LastRow(dwb.Worksheets("Sheet1")) + 1
Set sr = ThisWorkbook.Worksheets("DEFAULTS").Range("U2:AB2")
Sheets("Sheet1").Select
Set dr = dwb.Worksheets("Sheet1").Range("A" & Lr)
sr.Copy
dr.PasteSpecial xlPasteValues, , False, False
Application.CutCopyMode = False
Sheets("Sheet1").Select
Range("E2").Select
'**************************************************************
dwb.Close True
Application.ScreenUpdating = False
'***********************************************************
'SAVE AS AS READ ONLY
SetAttr " C:\Test\Pants\color.xls ", vbReadOnly
'**********************************************************
'******************END PROGRAM*****************************
suppose to archive the data (color.xls) is open my program crashes. I would
like to know if the program can recognize the following:
If the color.xls file is open then close it. So the program can be run
without problem.
Thanks in advance.
Maperalia.
'********************START PROGRAM************************
'CREATE DATABASE
Dim sr As Range
Dim dr As Range
Dim dwb As Workbook
Dim Lr As Long
Dim hl As String
'Where:
'Lr = Last Row
'dr = destination Range
'dwb = destination WorkBook
'sr = source range
'***************************************************
'***************************************************
'OPEN THE FILE TO ARCHIVE INFORMATION
Application.ScreenUpdating = False
If bIsBookOpen("color.xls") Then
Set dwb = Workbooks("color.xls")
Else
'***************************************************
'REMOVE READ ONLY
SetAttr "C:\Test\Pants\color.xls", vbNormal
'***************************************************
Set dwb = Workbooks.Open("C:\Test\Pants\color.xls ")
End If
'***************************************************************
'WRITE THE DATABASE
UserForm1.Repaint
Application.ScreenUpdating = False
UserForm1.Repaint
Lr = LastRow(dwb.Worksheets("Sheet1")) + 1
Set sr = ThisWorkbook.Worksheets("DEFAULTS").Range("U2:AB2")
Sheets("Sheet1").Select
Set dr = dwb.Worksheets("Sheet1").Range("A" & Lr)
sr.Copy
dr.PasteSpecial xlPasteValues, , False, False
Application.CutCopyMode = False
Sheets("Sheet1").Select
Range("E2").Select
'**************************************************************
dwb.Close True
Application.ScreenUpdating = False
'***********************************************************
'SAVE AS AS READ ONLY
SetAttr " C:\Test\Pants\color.xls ", vbReadOnly
'**********************************************************
'******************END PROGRAM*****************************