Arrays 文件取消共享并再次共享时宏不工作
我正在尝试向共享excel二进制工作簿的文件中添加几个简单的宏。问题是,每当文件取消共享时,宏将不再工作。代码如下:Arrays 文件取消共享并再次共享时宏不工作,arrays,excel,vba,Arrays,Excel,Vba,我正在尝试向共享excel二进制工作簿的文件中添加几个简单的宏。问题是,每当文件取消共享时,宏将不再工作。代码如下: Sub uploadMain() Dim xlsFile As String Dim wbResults As Workbook Dim wbmCall As Workbook Dim agmtCdCell As Range Dim amtCldCell As Range Dim srchRa
Sub uploadMain()
Dim xlsFile As String
Dim wbResults As Workbook
Dim wbmCall As Workbook
Dim agmtCdCell As Range
Dim amtCldCell As Range
Dim srchRange As Integer
Dim callClmn As Integer
Dim srchString As String
Dim callAmt As String
Dim notFound As String
Dim lastRowNo As Long
Dim srchRowNo As Long
Dim srcRowNo As Long
Dim customView As Boolean
Dim amntReplaced As Boolean
Dim asset_column As Integer
Dim typ
Dim quantity_column As Integer
Dim quantity As Variant
Dim unique_identifier As Integer
Dim lastrow_updated As Integer
Dim lastrow_preupload As Integer
Dim wiersz
Dim asset As String
Dim state As String
Dim old_row As Integer
Dim amp As String
Dim loaded
Dim direction_column As Integer
Dim delivery_type As String
Sheets("Calls").Select
ThisWorkbook.Save
customView = False
amntReplaced = False
Application.ScreenUpdating = False
Set wbmCall = ThisWorkbook
asset_column = Cells.Find(What:="Asset", After:=[A1], LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Column
quantity_column = Cells.Find(What:="Quantity", After:=[A1], LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Column
srchRange = Cells.Find(What:="Agmt Code", After:=[A1], LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Column
direction_column = Cells.Find(What:="Direction", After:=[A1], LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Column
xlsFile = Application.GetOpenFilename("Excel Workbooks (*.xls; *.xlsx),*.xls;*.xslx", , "Select Acadia extract to import.", , False)
If xlsFile = "False" Then Exit Sub
Set wbResults = Workbooks.Open(Filename:=xlsFile, UpdateLinks:=0)
' call amtcalled removed
Dim relocList() As Variant
Dim lngPosition As Integer
Dim startingRow As Range
Dim i As Long
Dim temporary_row As Integer
wbmCall.Activate
Dim b As Integer
Sheets("AcadiaFeeds").Select
Dim amp_array()
If Range("J65536").End(xlUp).Row > 2 Then
Cells(Range("J65536").End(xlUp).Row, 10).Select 'last row
lastrow_preupload = Range("J65536").End(xlUp).Row
amp_array = Range(Selection, Selection.End(xlUp))
End If
wbResults.Activate
'________________
For i = 2 To lastrow_preupload
If Range("Z" & i).Value = "Deliver" Then
ActiveSheet.Range("E" & i).Select
Selection.Replace What:="GROSS", Replacement:="OTM", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
Else
ActiveSheet.Range("E" & i).Select
Selection.Replace What:="GROSS", Replacement:="ITM", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
End If
Next i
'_______________________
relocList = Array("Margin Call Amp ID", "Delivery Type", "Amp ID", "Call Type", "Business State", "Valuation Date", "Total Call Amount", "Our Unique Agreement Identifier", "Quantity", "FX Currency", "Security Id", "Type")
Stop
For lngPosition = LBound(relocList) To UBound(relocList)
Set startingRow = ActiveSheet.Rows(1).Find(What:=relocList(lngPosition), After:=[A1], LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False)
If Not startingRow Is Nothing Then
Columns(startingRow.Column).Select
Selection.Cut
Columns(1).Select
Selection.Insert Shift:=xlToRight
End If
Next lngPosition
Columns(13).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete
Dim nextone As String
j = 1
i = 2
Do Until i = Range("A65000").End(xlUp).offset(1, 0).Row
If Cells(i, 8).Value = "Partial Disputed" Then
Rows(i).Delete
Else
i = i + 1
End If
If Cells(i, 11).Value = "Deliver" Then Cells(i, 11).Value = "Pledge"
If Cells(i, 1).Value = "PLEDGE" Then
temporary_row = WorksheetFunction.Match(Cells(i, 12), Range("J:J"), 0)
Cells(i, 5) = Cells(temporary_row, 5)
Cells(i, 8) = Cells(temporary_row, 8)
End If
Loop
Dim As String
i = 1
'remove blanks
=======================================================================================================================================================
lastRowNo = Range("A65000").End(xlUp).Row
wbmCall.Activate
Sheets("AcadiaFeeds").Select
If ActiveSheet.FilterMode = True Then ActiveSheet.FilterMode = False 'gdyby komus wpadl do lepetyny glupi pomysl dodawania filtra w Acadia Feeds
srchRowNo = Range("A65000").End(xlUp).Row + 5
If srchRowNo < 10 Then
srchRowNo = 10
lastrow_preupload = 10
End If
Range("L" & srchRowNo).Value = "Uploaded " & Format(Now, "mmm dd, yyyy hh:mm:ss") & " by " & LCase(Environ("USERNAME"))
srcRowNo = 1
i = 1
Do Until i > lastRowNo
Range("A" & srchRowNo & ":K" & srchRowNo).Value = wbResults.Sheets(1).Range("A" & srcRowNo & ":K" & srcRowNo).Value
srchRowNo = srchRowNo + 1
srcRowNo = srcRowNo + 1
i = i + 1
Loop
wbResults.Close SaveChanges:=False
Set wbResults = Nothing
wbmCall.Activate
Set wbmCall = Nothing
ActiveWorkbook.Sheets("Calls").Select
If ActiveSheet.AutoFilterMode = True Then
customView = True
Application.EnableEvents = False
ActiveWorkbook.CustomViews.Add ViewName:="doAcadii", RowColSettings:=True
ActiveSheet.AutoFilterMode = False
Application.EnableEvents = True
End If
ActiveWorkbook.Sheets("AcadiaFeeds").Select
callClmn = 5 'Our Unique Agreement Identifier na sztywno
cTypeClmn = 9 'call type na sztywno w kolumnie 5tej
=======================================================================================================================================================
backAtLoop:
srchRowNo = lastrow_preupload
lastrow_updated = Range("A65000").End(xlUp).Row
Do Until srchRowNo = lastrow_updated + 1
ActiveWorkbook.Sheets("AcadiaFeeds").Select
srchRowNo = srchRowNo + 1
amp = Cells(srchRowNo, callClmn + 5).Value ' amp ID
srchString = Cells(srchRowNo, callClmn).Value 'od dolu bierze unique identifier
callAmt = Cells(srchRowNo, callClmn + 1).Value 'amt called
cType = Cells(srchRowNo, cTypeClmn).Value 'call type
quantity = Cells(srchRowNo, callClmn - 1).Value 'ilosc papierow
state = Cells(srchRowNo, callClmn + 3).Value 'business state pledge accepted
delivery_type = Cells(srchRowNo, callClmn + 6)
typ = Cells(srchRowNo, 1).Value 'margin_call lub pledge
If Cells(srchRowNo, callClmn - 3).Value <> "CASH" Then
asset = Cells(srchRowNo, callClmn - 3).Value ' aktywo
Else:
asset = Cells(srchRowNo, callClmn - 2).Value
End If
Sheets("Calls").Select
Set foundmatchx = Columns(srchRange).Find(What:=srchString, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)
If typ = "MARGIN_CALL" Then
If Application.WorksheetFunction.CountIf(Columns(srchRange), srchString) = 0 Then 'sprawdza dany agreement jest w mcalls table
Sheets("AcadiaFeeds").Select
notFound = notFound & "; " & srchString
Range("A" & srchRowNo & ":I" & srchRowNo).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("K" & srchRowNo).Value = "Not Found"
ElseIf Application.WorksheetFunction.CountIf(Columns(srchRange), srchString) <> 0 Then
'howMany = Application.WorksheetFunction.CountIf(Columns(srchRange), srchString)
foundmatchx.offset(0, 3).Activate ' aktywuje offset AMT called
If ActiveCell.offset(0, 11) = "Initial" And cType = "Initial" Then 'idk nor care
'nowt to do here
ElseIf cType = "Initial" And Right(srchString, 4) <> "FBCO" Then
ActiveWorkbook.Sheets("AcadiaFeeds").Select 'acadia feeds
Range("A" & srchRowNo & ":E" & srchRowNo).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 49407
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("F" & srchRowNo).Value = "IM call not found"
GoTo nexxtSrchRowNo
ElseIf cType = "Initial" And Right(srchString, 4) = "FBCO" Then
'nowt to do here
Else
Columns(srchRange).FindNext(foundmatchx).offset(0, 3).Activate
End If
Range("J" & srchRowNo).Value = "Already Loaded", Range("A" & srchRowNo & ":I" & srchRowNo).Select
If ActiveCell.Value = callAmt Then
ActiveWorkbook.Sheets("AcadiaFeeds").Select 'acadia feeds
With ActiveWorkbook.Sheets("AcadiaFeeds").Range("A" & srchRowNo & ":I" & srchRowNo).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5296274
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("K" & srchRowNo).Value = "Already Loaded"
ElseIf ActiveCell.Value <> "" And ActiveCell.Value <> callAmt Then
ActiveWorkbook.Sheets("AcadiaFeeds").Select 'acadia feeds
Range("A" & srchRowNo & ":E" & srchRowNo).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 49407
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Range("K" & srchRowNo).Value = "Loaded w/ different amt - please investigate"
amntReplaced = True
Else
ActiveCell.Value = callAmt
ActiveCell.offset(0, 20).Value = "loaded from AcadiaFeeds sheet row# " & srchRowNo
End If
Else
MsgBox "Something unexpected happend"
End If
nexxtSrchRowNo:
End If
ActiveWorkbook.Sheets("AcadiaFeeds").Select
If typ = "PLEDGE" Then
Sheets("Calls").Select 'calls
wiersz = foundmatchx.Row
If IsVarArrayEmpty(amp_array) = False Then
j = 1
loaded = "not_loaded"
For j = 1 To UBound(amp_array)
If amp_array(j, 1) = amp Then
loaded = "already_loaded"
j = UBound(amp_array)
End If
Next
Else: loaded = "not_loaded"
End If
Select Case loaded
Case "already_loaded"
If state = "Pledge Accepted" Then
If IsEmpty(Cells(wiersz, quantity_column)) = False And quantity <> Cells(wiersz, quantity_column) Then
Application.Union(Range(Cells(wiersz + 1, srchRange - 2), Cells(wiersz + 1, srchRange - 1)), Range(Cells(wiersz + 1, srchRange + 1), Cells(wiersz + 1, srchRange + 2))).Style = "Good"
Else:
Application.Union(Range(Cells(wiersz, srchRange - 2), Cells(wiersz, srchRange - 1)), Range(Cells(wiersz, srchRange + 1), Cells(wiersz, srchRange + 2))).Style = "Good"
End If
End If
Case "not_loaded"
If delivery_type = Cells(wiersz, direction_column) And IsEmpty(Cells(wiersz, quantity_column)) = True Then
If state = "Pledge Accepted" Then
Application.Union(Range(Cells(wiersz, srchRange - 2), Cells(wiersz, srchRange - 1)), Range(Cells(wiersz, srchRange + 1), Cells(wiersz, srchRange + 2))).Style = "Good"
End If
Cells(wiersz, quantity_column) = quantity
Cells(wiersz, asset_column) = asset
ElseIf delivery_type = Cells(wiersz, direction_column) And IsEmpty(Cells(wiersz, quantity_column)) = False Then
Cells(wiersz, quantity_column).Select
Call MainModule.insertRow
Cells(wiersz + 1, quantity_column) = quantity
Cells(wiersz + 1, asset_column) = asset
If state = "Pledge Accepted" Then
Application.Union(Range(Cells(wiersz + 1, srchRange - 2), Cells(wiersz + 1, srchRange - 1)), Range(Cells(wiersz + 1, srchRange + 1), Cells(wiersz + 1, srchRange + 2))).Style = "Good"
End If
ElseIf delivery_type <> Cells(wiersz, direction_column) Then
howMany = Application.WorksheetFunction.CountIf(Columns(srchRange), srchString)
i = 1
For i = 1 To howMany
Set foundmatchx = Columns(srchRange).FindNext(foundmatchx)
'daje find dla danego agreeementu
temporary_row = foundmatchx.Row
If delivery_type = Cells(temporary_row, direction_column) And IsEmpty(Cells(temporary_row, quantity_column)) = True Then
'1_17 change
If state = "Pledge Accepted" Then
Application.Union(Range(Cells(temporary_row, srchRange - 2), Cells(temporary_row, srchRange - 1)), Range(Cells(temporary_row, srchRange + 1), Cells(temporary_row, srchRange + 2))).Style = "Good"
End If
Cells(temporary_row, quantity_column) = quantity
Cells(temporary_row, asset_column) = asset
i = howMany
End If
Next
End If
End Select
End If
Loop
ActiveWorkbook.Sheets("Calls").Select
'aplikuje filtr spowrotem
If customView = True Then
Application.EnableEvents = False
With ActiveWorkbook.CustomViews("doAcadii")
.Show
.Delete
End With
Application.EnableEvents = True
End If
Application.ScreenUpdating = True
'ponizsze IF dodane 07/30
If amntReplaced = True Then
MsgBox "Acadia extract uploaded, but some calls were loaded with different call amounts." & vbCrLf & _
"Please investigate for issues before saving this spreadsheet."
Else
MsgBox "Acadia extract uploaded!"
End If
End Sub
Sub amtsCalled()
Application.ScreenUpdating = False
Dim relocList() As Variant
Dim lngPosition As Integer
Dim startingRow As Range
Dim i As Long
Dim temporary_row As Integer
wbmCall.Activate
Sheets("AcadiaFeeds").Select
Dim amp_array()
Cells(Range("J65536").End(xlUp).Row, 10).Select 'last row
MsgBox (Cells(Range("J65536").End(xlUp).Row, 10))
amp_array = Range(Selection, Selection.End(xlUp))
wbResults.Activate
relocList = Array("Margin Call Amp ID", "Amp ID", "Call Type", "Business State", "Valuation Date", "Total Call Amount", "Our Unique Agreement Identifier", "Quantity", "FX Currency", "Security Id", "Type")
Stop
For lngPosition = LBound(relocList) To UBound(relocList)
Set startingRow = ActiveSheet.Rows(1).Find(What:=relocList(lngPosition), After:=[A1], LookIn:=xlValues, LookAt:=xlWhole, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False)
If Not startingRow Is Nothing Then
Columns(startingRow.Column).Select
Selection.Cut
Columns(1).Select
Selection.Insert Shift:=xlToRight
End If
Next lngPosition
Columns(12).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete
Dim nextone As String
i = 2
Do Until i = Range("A65000").End(xlUp).offset(1, 0).Row
For j = 1 To UBound(amp_array)
If Cells(i, 10).Value = amp_array(j, 1) Then GoTo nextone
Next
If Cells(i, 8).Value = "Partial Disputed" Then
Rows(i).Delete
Else
i = i + 1
End If
If Cells(i, 1).Value = "PLEDGE" Then
temporary_row = WorksheetFunction.Match(Cells(i, 11), Range("J:J"), 0)
Cells(i, 5) = Cells(temporary_row, 5)
End If
nextone:
Loop
'remove blanks
On Error GoTo 0
Exit Sub
Application.ScreenUpdating = True
End Sub
Sub ss()
Application.ScreenUpdating = True
End Sub
Function IsVarArrayEmpty(anArray As Variant)
Dim i As Integer
On Error Resume Next
i = UBound(anArray, 1)
If Err.Number = 0 Then
IsVarArrayEmpty = False
Else
IsVarArrayEmpty = True
End If
End Function
Sub-uploadMain()
将xlsFile设置为字符串
将结果设置为工作簿
将wbmCall设置为工作簿
变暗agmtCdCell As范围
Dim amtCldCell As范围
作为整数的Dim srchRange
Dim CALLCMN作为整数
将srchString设置为字符串
作为字符串的Dim callAmt
找不到字符串
暗淡的最后一行没有那么长
变暗srchRowNo为长
没有那么长
将自定义视图设置为布尔值
Dim AMN替换为布尔值
将列设置为整数
模糊类型
Dim quantity_列为整数
变暗量
Dim唯一_标识符为整数
Dim lastrow_更新为整数
Dim lastrow\u预上载为整数
迪姆·维尔兹
将资产设置为字符串
暗状态为字符串
将旧行变暗为整数
作为字符串的Dim amp
昏暗的
Dim方向_列为整数
Dim传递类型为字符串
工作表(“呼叫”)。选择
此工作簿。保存
customView=False
amntReplaced=False
Application.ScreenUpdating=False
设置wbmCall=ThisWorkbook
asset_column=Cells.Find(What:=“asset”,After:=[A1],LookIn:=xlValues,LookAt:=xlother,SearchOrder:=xlByRows,SearchDirection:=xlNext_
MatchCase:=False)。列
数量_列=单元格。查找(内容:=“数量”,后面:=[A1],查找:=xlValues,查找:=xlother,搜索顺序:=xlByRows,搜索方向:=xlNext_
MatchCase:=False)。列
srchRange=Cells.Find(What:=“Agmt代码”,After:=[A1],LookIn:=xlValues,LookAt:=xlother,SearchOrder:=xlByRows,SearchDirection:=xlNext_
MatchCase:=False)。列
方向列=单元格。查找(What:=“direction”,After:=[A1],LookIn:=xlValues,LookAt:=xlother,SearchOrder:=xlByRows,SearchDirection:=xlNext_
MatchCase:=False)。列
xlsFile=Application.GetOpenFilename(“Excel工作簿(*.xls;*.xlsx),*.xls;*.xslx”,“选择要导入的Acadia提取”,False)
如果xlsFile=“False”,则退出Sub
设置wbResults=Workbooks.Open(文件名:=xlsFile,更新链接:=0)
'调用amtcall已删除
Dim relocList()作为变量
作为整数的Dim lngPosition
暗淡的起始行As范围
我想我会坚持多久
将临时行设置为整数
wbmCall.Activate
作为整数的Dim b
工作表(“AcadiaFeeds”)。选择
Dim amp_阵列()
如果范围(“J65536”).End(xlUp).Row>2,则
单元格(范围(“J65536”)。结束(xlUp)。第10行。选择“最后一行”
lastrow_preupload=范围(“J65536”).End(xlUp).Row
amp_数组=范围(选择,选择结束(xlUp))
如果结束
wbResults.激活
'________________
对于i=2到最后一行\u预上载
如果范围为(“Z”&i).Value=“交付”,则
ActiveSheet.Range(“E”和i)。选择
选择。替换内容:=“总量”,替换:=“OTM”,查看:=xlPart_
SearchOrder:=xlByRows,MatchCase:=False,SearchFormat:=False_
ReplaceFormat:=False,FormulaVersion:=xlReplaceFormula2
其他的
ActiveSheet.Range(“E”和i)。选择
选择。替换内容:=“总量”,替换:=“ITM”,查看:=xlPart_
SearchOrder:=xlByRows,MatchCase:=False,SearchFormat:=False_
ReplaceFormat:=False,FormulaVersion:=xlReplaceFormula2
如果结束
接下来我
'_______________________
relocList=数组(“保证金通知Amp-ID”、“交付类型”、“Amp-ID”、“通知类型”、“业务状态”、“估价日期”、“总通知金额”、“我们的唯一协议标识符”、“数量”、“外汇货币”、“证券ID”、“类型”)
停止
对于lngPosition=LBound(relocList)到UBound(relocList)
设置startingRow=ActiveSheet.Rows(1).Find(What:=relocList(lngPosition),After:=A1],LookIn:=xlValues,LookAt:=xlWhole_
SearchOrder:=xlByColumns,SearchDirection:=xlNext,MatchCase:=False)
如果没有开始,那么Row算不了什么
列(startingRow.Column)。选择
选择,剪
列(1)。选择
选择。插入移位:=xlToRight
如果结束
下一个位置
列(13)。选择
范围(选择,选择。结束(xlToRight))。选择
选择。删除
作为字符串的暗色调
j=1
i=2
直到i=范围(“A65000”)。结束(xlUp)。偏移量(1,0)。行
如果单元格(i,8).Value=“部分有争议”,则
第(i)行。删除
其他的
i=i+1
如果结束
如果单元格(i,11).Value=“交付”,则单元格(i,11).Value=“质押”
如果单元格(i,1).Value=“质押”,则
临时行=工作表函数.Match(单元格(i,12),范围(“J:J”),0)
单元格(i,5)=单元格(临时行,5)
单元(i,8)=单元(临时行,8)
如果结束
环
朦胧
i=1
“去掉空白
=======================================================================================================================================================
lastRowNo=范围(“A65000”)。结束(xlUp)。行
wbmCall.Activate
工作表(“AcadiaFeeds”)。选择
如果ActiveSheet.FilterMode=True,则ActiveSheet.FilterMode=False“gdyby komus wpadl do lepetyny glupi pomysl dodawania filtra w Acadia Feed
srchRowNo=范围(“A65000”)。结束(xlUp)。行+5
如果srchRowNo<10,则
srchRowNo=10
lastrow_预上传=10
如果结束
范围(“L”和srchRowNo).Value=“upload”和格式(现在是“mmmdd,yyyy hh:mm:ss”)、“by”和LCase(环境(“用户名”))
srcRowNo=1
i=1
直到我最后一次来
范围(“A”&srcRowNo&“:K”&srcRowNo).Value=wbResults.Sheets(1).范围(“A”&srcRowNo&“:K”&srcRowNo).Value
srchRowNo=srchRowNo+1
srcRowNo=srcRowNo+1
i=i+1
环
wbResults.Close SaveChanges:=False
设置wbResults=Nothing
wbmCall.Activate
设置wbmCall=Nothing
ActiveWorkbook.Sheets(“调用”)。选择
中频交流