Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1601|回复: 5

[已解决]再次求助,代碼修改

[复制链接]
发表于 2016-4-28 09:31 | 显示全部楼层 |阅读模式
本帖最后由 心正意诚身修 于 2016-4-28 15:50 编辑

昨天有個發了個求助。有老師幫我完成了。昨天的要求是模擬是直接一排顯示下去,現在要按三排。附件有模擬結果。麻煩老師們再幫我改改。
因為我這裡是繁體版。附件到我這裡是看不見漢字的。全是亂碼,老師帖的時候最好帖代碼進去,遇到漢字。我可以重新打一敲。謝謝老師們了。
最佳答案
2016-4-28 15:11
safd23g3.gif

3.rar (1.65 MB, 下载次数: 6)

LOGO資料.rar

151.16 KB, 下载次数: 9

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2016-4-28 10:48 | 显示全部楼层
Option Explicit

'**************************************************************************************
'功能:A列和C列返回图片数据,B列插入图片
'http://www.excelpx.com/thread-417091-1-1.html
'http://www.excelpx.com/thread-417105-1-1.html
Sub checkLogo()
    Dim A()
    Dim path As String
    Dim file As String
    Dim i As Integer
    Dim r As Integer    '实际行号
    Dim c As Integer    '实际列号
    Dim x As Integer    '一行几组(1个logo1个图片1个user为1组)


    Application.ScreenUpdating = False
    Call init
    path = ThisWorkbook.path & "\LOGO圖檔\"
    file = Dir(path)
    x = 3
    ReDim A(1 To 10 ^ 4, 1 To 3 * x)


    Do While file <> ""
        '将i转为实际行列
        i = i + 1
        r = getRow(i, x) + 1    '因为有1行标题,所以下移1行
        c = getColumn(i, x)
        c = (c - 1) * 3 + 2

        '插入图片。自行统一单元格的列宽和行高
        With Cells(r, c)
            ActiveSheet.Shapes.AddPicture _
                    Filename:=path & file, LinkToFile:=True, SaveWithDocument:=False, _
                    Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height
        End With

        '录入信息
        file = Left(file, Len(file) - 4)
        If InStr(file, "-") Then
            A(r, c - 1) = VBA.Split(file, "-")(0)    'logo
            A(r, c + 1) = VBA.Split(file, "-")(1)    'user
        Else
            A(r, c - 1) = file
        End If
        file = Dir
    Loop


    [a1].Resize(r, UBound(A, 2)) = A
    For i = 1 To UBound(A, 2) Step 3
        Cells(1, i).Resize(1, 3) = Array("LOGO#", "圖案", "客戶")
    Next i
    Call SetOnAction    '可选功能
End Sub

'单击时被执行的宏
Private Sub SetOnAction()
    Dim shp As Shape
    For Each shp In ActiveSheet.Shapes
        If shp.Type = msoLinkedPicture Then shp.OnAction = "ActionClick"
    Next
End Sub

'单击时的动作
Private Sub ActionClick()
    Dim zoom As Integer
    zoom = 3    '指定放大系数
    With ActiveSheet.Shapes(Application.Caller)
        .ZOrder msoBringToFront
        If .Width = Range("b:b").Width Then    '指定图片的列
            .Width = .Width * zoom: .Height = .Height * zoom
        Else
            .Width = .Width / zoom: .Height = .Height / zoom
        End If
    End With
End Sub

'获取行
Function getRow(x, y)
    getRow = IIf(x \ y = x / y, x \ y, x \ y + 1)
End Function

'获取列
Function getColumn(x, y)
    getColumn = IIf(x Mod y, x Mod y, y)
End Function

'初始化(清除操作)
Private Sub init()
    With Cells
        .Clear
        .RowHeight = 100
        .ColumnWidth = 18
    End With
    Rows(1).RowHeight = 27
    ActiveSheet.Pictures.Delete
End Sub

2.rar (119.83 KB, 下载次数: 5)
回复

使用道具 举报

 楼主| 发表于 2016-4-28 13:06 | 显示全部楼层
愛瘋老師,在運行的時候,這句出錯。說是未定義。

    [a1].Resize(r, UBound(A, 2)) = A
麻煩再看下。上午開會。
回复

使用道具 举报

 楼主| 发表于 2016-4-28 13:07 | 显示全部楼层
爱疯 发表于 2016-4-28 10:48
Option Explicit

'******************************************************************************** ...

麻煩看下,我該怎麼改呢,惟一的變化是。現在的圖片是722張。
回复

使用道具 举报

发表于 2016-4-28 15:11 | 显示全部楼层    本楼为最佳答案   
safd23g3.gif

3.rar (1.65 MB, 下载次数: 6)

点评

已解決了。謝謝愛瘋版主。辛苦了。  发表于 2016-4-28 15:49
回复

使用道具 举报

 楼主| 发表于 2016-4-28 15:20 | 显示全部楼层
爱疯 发表于 2016-4-28 15:11
1)代码没改
2)用1024个图片测试,没发现报错啊?要不你发一个执行出错的动画

現在圖片過來了。可是原檔案的名字。。沒出來。。公司電腦,錄不了GIF。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-26 07:08 , Processed in 0.510446 second(s), 14 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表